Trying to plot array points on a graph.
24 次查看(过去 30 天)
显示 更早的评论
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
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
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');
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!