Trying to plot array points on a graph.

조회 수: 32 (최근 30일)
David Haller
David Haller 2022년 10월 7일
답변: Jim Riggs 2022년 10월 7일
I have an matrix that I am trying to turn into a picture using the graphing function. it is a 10x10 matrix with numbers ranging from 0 to 5 and I'm trying to figure out how to plot only certain points with the array itself serving as my x/y axis. I have tried the graphing function as well as nesting a loop function to allow for the figure, but I'm still coming up with nothing.
right now my matrix is as follows:
0 0 0 0 0 0 5 0 5 0
0 0 0 2 0 0 0 0 0 0
0 2 0 1 0 4 2 1 3 0
0 1 0 1 0 0 0 0 0 0
4 3 0 1 0 0 0 0 0 0
4 0 0 3 0 3 1 1 2 0
0 0 5 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 3 1 1 1 2 0 0 4 0
0 0 0 0 4 0 0 5 0 0
if anyone can help isolare the non-zero values to use as data points i would be most grateful.
  댓글 수: 1
Jim Riggs
Jim Riggs 2022년 10월 7일
편집: Jim Riggs 2022년 10월 7일
Try This:
Assume that AA is the matrix of data
[row,col] = size(AA);
figure;
for ii=1:row
for jj=1:col
if AA(ii,jj) > 0 % specify criterion for the points you want to plot
plot(jj, col-ii, 'or', 'LineWidth',1.5,'MarkerSize',10)
hold on;
end
end
end
hax = gca;
set (hax, 'Xlim', [0 col+1], 'Ylim', [0 row+1]);
grid on;
title('Non-zero Values');
xlabel('Column');
ylabel('Row');

댓글을 달려면 로그인하십시오.

답변 (1개)

Jim Riggs
Jim Riggs 2022년 10월 7일
You might also try this:
[row,col] = size(AA); % AA is the data matrix
figure;
for ii=1:row
for jj=1:col
if AA(ii,jj) > 0 % specify criterion for the points you want to plot
plot(jj, col-ii, 'or', 'LineWidth',1.5,'MarkerSize',10)
hold on;
else
plot(jj, col-ii, 'xk', 'LineWidth',0.5,'MarkerSize',6)
hold on;
end
end
end
hax = gca;
set (hax, 'Xlim', [0 col+1], 'Ylim', [0 row+1]);
grid on;
title('Non-zero Values');
xlabel('Column');
ylabel('Row');

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by