フィルターのクリア

Create a plot for a loop

3 ビュー (過去 30 日間)
Miguel Albuquerque
Miguel Albuquerque 2022 年 5 月 24 日
コメント済み: Miguel Albuquerque 2022 年 5 月 24 日
Hey guys, thanks in advance for reading this
I have this code, that finds in surv_matrix the indixes where the matrix is different from zero. but for each one of them indices, I want to create a plot, like that, and see one plot for each indice. Is there anyway of creating a better loop, since this one only gives me the last plot. Imagining that ic=3,4,5. I want to see 3 plots, and with this code I m only seeing 1.
Thank you,
ic=find(~all(surv_matrix==0));
for idx=ic
surveillance_column=surv_matrix(:,idx)
plot(abs(freq_XQPSK),(abs(surveillance_column)),'b','linewidth',2);
continue
end

回答 (1 件)

Mustafa Abu-Mallouh
Mustafa Abu-Mallouh 2022 年 5 月 24 日
編集済み: Mustafa Abu-Mallouh 2022 年 5 月 24 日
Use the 'hold on' command after your plot command, this will put all of your plots on the same axes
hold on
  3 件のコメント
Mustafa Abu-Mallouh
Mustafa Abu-Mallouh 2022 年 5 月 24 日
You should remove the color designation or at least have different designations for each iteration or else your plots will be the same color.
You also do not need the continue command, the for loop will automatically continue to the next value when it reaches the end of the iteration.
I'm not sure where you put the hold command but I get multiple lines on a single plot with the following
% Create random data with 0's in the third column
freq_XQPSK = (1:5)';
surv_matrix = rand(5,5);
surv_matrix(:,3) = 0;
% Find nonzero columns
ic=find(~all(surv_matrix==0));
% Loop
for idx=ic
surveillance_column = surv_matrix( : , idx );
figure(1) % I always designate a figure, especially when using hold commands
plot( abs(freq_XQPSK) , abs(surveillance_column) , 'LineWidth' , 2 ); hold on
end
Miguel Albuquerque
Miguel Albuquerque 2022 年 5 月 24 日
Alright im doing this:
In the case of my example, ic= 197,198,199,200,201,202,203 . But with this code im only seeing the last plot of ic=203, Is there anyway I could see all the 7 plots, without doing it mannually, which means, replacing ic myself.
ic=find(~all(surv_matrix==0));
for idx=ic
surveillance_column=surv_matrix(:,idx);
figure(1);
plot(abs(freq_XQPSK),(abs(surveillance_column)),'b','linewidth',2); hold on
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by