이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)