現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
how to save plots so that they are in the same graph for different conditions
1 回表示 (過去 30 日間)
古いコメントを表示
Priya
2014 年 7 月 25 日
Hi,
I need to generate plots for four different conditions. So I will be having four curves on the whole. Now I get a plot for the first condition, and when I change the condition, I obviously get a different plot but I need to make the first plot remain in the same graph. Similarly for the third and fourth graphs (or conditions).
Please someone tell me how to do this. I have tried the 'hold on' command, nothing happens.
Thanks.
採用された回答
Star Strider
2014 年 7 月 25 日
編集済み: Star Strider
2014 年 7 月 25 日
If you want them all in the same set of axes, and hold did not work, post your code so we can see what you did and what the problem is.
Later, with posted code available...
One problem is that you’re not telling it to plot the correct vector. See if changing the plot command to:
plot(s_x_index, f_x_save, 'x')
improves things.
34 件のコメント
Priya
2014 年 7 月 25 日
Thanks. Please find the code. I haven't posted everything, Just the conditions and the loop, thinking this is enough to explain.
Star Strider
2014 年 7 月 25 日
My pleasure! See my edited Answer under ‘Later, with posted code available...’
Star Strider
2014 年 7 月 25 日
編集済み: Star Strider
2014 年 7 月 25 日
You’re only plotting one plot. That’s all you can do with the code you posted. If randomindex has something to do with it, you may need to create f_x_save as a matrix using randomindex as well:
f_x_save(randomindex,i) = f_x;
and then loop through f_x_save incrementing randomindex to get all four plots:
figure(5)
for k = 1:size(f_x_save,1)
plot(s_x_index, f_x_save(k,:), 'x')
hold on
end
hold off
Star Strider
2014 年 7 月 25 日
Just use this line, as I suggested in my previous Comment:
f_x_save(randomindex,i) = f_x;
There is no reason to save f_x separately if you are saving it in the f_x_save matrix.
Priya
2014 年 7 月 25 日
Yes I did. But on doing so, It gives
Subscripted assignment dimension mismatch.
Error in test_contact_ellipse (line 402)
f_x_save(randomIndex,i) = f_x;
Star Strider
2014 年 7 月 25 日
I don’t have all the information to run your code. What size is f_x? Is it a scalar (that I assumed) or a vector?
Star Strider
2014 年 7 月 25 日
That’s the problem.
Change the f_x_save line to:
f_x_save(randomIndex,:) = f_x;
That should work with the rest of the code I posted as well.
Priya
2014 年 7 月 25 日
Thanks it works partially now. But I need all 4 plots to use the same axis limits.
The problem now is, its changing the axis by itself which in turn affects the other plots.
Star Strider
2014 年 7 月 25 日
The easiest way to do that is to use the axis function. Set the axis limits to the values that accommodate all your plot data.
Star Strider
2014 年 7 月 25 日
According to the legend, all four are actually plotted.
Change the plotting loop to:
figure(5)
hold on
for k = 1:size(f_x_save,1)
plot(s_x_index, f_x_save(k,:), 'x')
end
hold off
See if that works.
Priya
2014 年 7 月 25 日
Not again.Yes it plots all the four, but the thing is when it plots for one condition the other is as shown at zero.
Star Strider
2014 年 7 月 25 日
OK. Abandon the loop and just go with this but outside (after) the loop:
figure(5)
plot(s_x_index, f_x_save, 'x')
grid
Star Strider
2014 年 7 月 25 日
I’m out of ideas. There must be something in your code that calculates them that is the problem.
Just after the f_x line, put:
minmax(randomindex,:) = [min(f_x) max(f_x)];
This is a way of determining where the problem is. If those values are different from the plotted values, the problem may be in the f_x_save matrix somewhere.
Star Strider
2014 年 7 月 25 日
編集済み: Star Strider
2014 年 7 月 25 日
OK, now do:
minmax2 = [min(f_x_save,[],2) max(f_x_save,[],2)]
after the loop and see what that is. It should be the same as minmax. If it isn’t, the problem is in f_x_save.
Star Strider
2014 年 7 月 25 日
If they’re the same and have the appropriate values, I have no idea why the plot is not working as you believe it should. I would use:
figure(5)
plot(s_x_index, f_x_save, 'x')
grid
after the loop and without the axis statement and see how the plot looks.
Star Strider
2014 年 7 月 27 日
編集済み: Star Strider
2014 年 8 月 6 日
Please post the entirety of your new code. I still have the old data file, but the code you posted isn’t what you are currently running.
EDIT — Turns out you simply need a loop with randomIndex:
[PLOT REMOVED]
I also attached your (slightly edited) test_contact_ellipse.m script file.
——————————
NOTE (06 Aug 2014) — After several weeks (in some instances) it turns out that OP’s posted code and data in this and other Questions are proprietary. At OP’s request, I have removed them from this Comment.
Star Strider
2014 年 7 月 27 日
編集済み: Star Strider
2014 年 7 月 27 日
Please see my previous comment. Is it what you want?
EDIT —
For clarity, this line becomes Line #307 in the code you posted in your ‘25 Jul 2014 at 12:14’ Comment:
for randomIndex = 1:4 % START ‘randomIndex’ LOOP
with this line then becoming Line #428:
end % END ‘randomIndex’ LOOP
Those were the only changes I made.
Star Strider
2014 年 7 月 27 日
My pleasure!
Your entire plotting loop becomes:
cs = {'^b'; 'pg'; 'sr'; 'vk'};
figure(5);
% for k = 1:size(f_x_save,1)
for k = 1:4
plot(s_x_index, f_x_save(k,:), cs{k} )
xlabel('Longitudinal creepage');ylabel('coefficient of adhesion')
hold on;
end
axis([0 0.02 0 0.6])
hold off
legend('Dry','Wet','Low','VLow')
Change the colours and symbols to your choices. They are defined in the ‘cs’ (colour-symbol) cell array. I chose a cell in the event you want to change the lengths of any of the elements, such as to connect some or all of the symbols in any set with lines, for instance '--b^' to connect the first set with a dashed blue line. The cell array will accomodate different sizes of the individual entries.
Star Strider
2014 年 8 月 6 日
I can remove them, but would prefer not to in case others have a similar problem and are looking for a solution.
I am moved to ask the reason for your request. There are nothing with respect to either of them that I would consider in any way offensive, the one criterion I would use to remove them immediately.
Priya
2014 年 8 月 25 日
Hi StarStrider,
Could you please find the link below, and help me. I have moved onto a different stage of this program now.
Can you please help me?
Thanks
Star Strider
2014 年 8 月 25 日
I would like to, but I haven’t used Simulink in a while. It would take me at least several days if not weeks to become proficient enough in it again to be able to solve problems regarding Simulink programming. Be sure to put Simulink in the ‘Products’ tag window so that people proficient in Simulink will see it.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)