Trying to plot array points on a graph.

30 Ansichten (letzte 30 Tage)
David Haller
David Haller am 7 Okt. 2022
Beantwortet: Jim Riggs am 7 Okt. 2022
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 Kommentar
Jim Riggs
Jim Riggs am 7 Okt. 2022
Bearbeitet: Jim Riggs am 7 Okt. 2022
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');

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jim Riggs
Jim Riggs am 7 Okt. 2022
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');

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by