converting Matlab plot example

1 次查看(过去 30 天)
The matlab example page provides which plots 1 value for the maxima and minima on a line graph I am trying to convert it but this doesnt seem to work.
Matlab page example1
x = 1:100;
y = rand(100,1);
idxmin = find(y == max(y));
idxmax = find(y == min(y));
plot(x,y,'-p','MarkerIndices',[idxmin idxmax],...
'MarkerFaceColor','red',...
'MarkerSize',15)
I am trying to convert it to ignore the maximas and plot more than 1 value for the minima
trop =[0.2571;-0.9444;-1.3218;0.9248;0.0000;-0.0549;0.9111;0.5946;0.3502;1.2503;0.9298;0.2398;-0.6904;-0.6516;1.1921;-1.6118;-0.0245;-1.9488;1.0205;0.8617;0.0012;-0.0708;-2.4863;0.5812;-2.1924]
minima = [-1.3218;-0.0549; 0.3502;-0.6904;-1.6118; -1.9488; -2.4863]
x = 1:length(trop);
y = trop;
idxmin = minima
plot(x,y,'-p','MarkerIndices',[idxmin],
'MarkerFaceColor','red',
'MarkerSize',15)
I'm not sure were im going wrong but I keep getting errors.

采纳的回答

Stephan
Stephan 2019-10-10
trop =[0.2571;-0.9444;-1.3218;0.9248;0.0000;-0.0549;0.9111;0.5946;0.3502;1.2503;0.9298;0.2398;-0.6904;-0.6516;1.1921;-1.6118;-0.0245;-1.9488;1.0205;0.8617;0.0012;-0.0708;-2.4863;0.5812;-2.1924]
minima = [-1.3218;-0.0549; 0.3502;-0.6904;-1.6118; -1.9488; -2.4863]
x = 1:length(trop);
y = trop;
idxmin = minima
plot(x,y,'-p','MarkerIndices',1:numel(minima),'MarkerFaceColor','red','MarkerSize',15)
  2 个评论
jacob Mitch
jacob Mitch 2019-10-10
Hi there thanks for you help, when I plot this in matlab I get maxima points as well, Is it possible to only match the minima to the lowest points on the plot of trop

请先登录,再进行评论。

更多回答(0 个)

类别

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