How do I plot a X-Y graph in matlab with data using "to workspace" block
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have 2 simulations and I took the data from both simulations and the data I wants is at out.xout{8} and out.yout{8} as a 1x1 double timeseries. How do I plot a X-Y graph out of these data? The code for retrieving data from "to workspace" block is as below:
clear all
close all
clc
%open system
open_system('circlex_ds');
%set parameters for x to workspace
set_param('circlex_ds/To Workspace',...
'VariableName','x')
%output the simulation results
out = sim('circlex_ds');
%plot function
figure()
plot(out.x)
x=out.xout{8};
%open system
open_system('circley_ds');
%set parameters for y to workspaae and for file
set_param('circley_ds/To Workspace',...
'VariableName','y')
%output the simulation results
out = sim('circley_ds');
%plot function
figure()
plot(out.y)
채택된 답변
Something like this
plot(out.xout{8}.Data, out.yout{8}.Data)
댓글 수: 13
I tried and it has following:
Error using to_workspace_file (line 28)
Brace indexing is not supported for variables of this type.
Is out.xout a time series? Maybe try this:
Change line to
out1 = sim('circlex_ds');
and
out2 = sim('circley_ds');
and then try
plot(out1.x.Data, out2.y.Data);
I changed and had following:
Error using plot
Vectors must be the same length.
Error in to_workspace_file (line 28)
plot(out1.x.Data, out2.y.Data,'same')
It shows both have a different number of elements. One solution is to use interpolation so that they have the same number of elements
x = out1.x.Data;
y = out2.y.Data;
y_interp = interp1(1:numel(y), y, linspace(1, numel(y), numel(x)));
plot(x, y_interp)
Is there another method, cause the output is suppose to be circle, but instead it turn out to be something like below

Can you attach the variables out1 and out2 in a .mat file?
There might be some problem with your simulation results. The variable you shared does not appear to be creating a circle. To create a circle, 'x' and 'y' must be sinusoidal signals individually, with a phase shift of 90 degrees. You can see that this is not the case with the data you shared.
Geoffrey Lo
2020년 6월 5일
편집: Geoffrey Lo
2020년 6월 5일
It should be a circle as I verified with the matlab code below and plot(out1.x) and plot(out2.y) just give the same results as the code.
If you plot out1.x.Data and then plot 'x' in your last script, you will see that they are not the same. Therefore, the Simulink output does not create a circle.
but when I use plot(out.x) and plot(out.y), it is the same as the x and y equation from circle_code_m
Oh! I forgot to consider that the time vector might not be equally spaced. Following will work
Time = linspace(0, 7, 1000);
x_interp = interp1(out1.x.Time, out1.x.Data, Time);
y_interp = interp1(out2.y.Time, out2.y.Data, Time);
plot(x_interp, y_interp)
it uses out1 and out2 you shared preiously.
Thanks a lot, it works now :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
참고 항목
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)
