# Trying to plot array points on a graph.

17 visualizzazioni (ultimi 30 giorni)
David Haller il 7 Ott 2022
Risposto: Jim Riggs il 7 Ott 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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Jim Riggs il 7 Ott 2022
Modificato: Jim Riggs il 7 Ott 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');

Accedi per commentare.

### Risposte (1)

Jim Riggs il 7 Ott 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');
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by