Plotting data of a 3x1xn array

3 次查看(过去 30 天)
Hi, I saved data of a simulation in to a 3x1xn cell array.
How can I plot each 3x1 instance Vs time. At the moment I manually saved data in to 3 separate variables in order to plot.
There could be a way to plot by extracting data straight from a n dimension cell.
refer to the comments on subplot(2,1,1)
clc;
clear all;
% Simulation settings
st=0.4; % simulation period in seconds
Ts=1e-6; % sampling period in seconds
t=0:Ts:st;
m=1;fo=50;
% initialize variables to increase simulation speed
o=zeros(1,numel(t));
d=zeros(1,numel(t));
q=zeros(1,numel(t));
for k=1:numel(t)
x=2*pi*fo*k*Ts; % theta
T= [1/2 1/2 1/2 ;... % transfer matrix
cos(x) cos(x-2*pi/3) cos(x+2*pi/3);...
sin(x) sin(x-2*pi/3) sin(x+2*pi/3)];
% 3 phase input signal
U=2/3*m*sin([x ; x- 2*pi/3 ; x+ 2*pi/3 ]);
% store values in 0dq matrix
o(k)=T(1,:)*U;
d(k)=T(2,:)*U;
q(k)=T(3,:)*U;
% odq(:,:,k)=T*U; % saving in to a cell array
end
% subplot(2,1,1);plot(t,odq); % what is the correct way plotting cell
% object defined in for loop.
subplot(2,1,1);plot(t,[o; d; q]);
y=2*pi*fo*t; % theta
U2=m*sin([y ; y- 2*pi/3 ; y+ 2*pi/3 ]);
subplot(2,1,2);plot(t,U2)
  2 个评论
Walter Roberson
Walter Roberson 2014-1-3
Your odq is not a 3 x 1 x n cell array: it is a 1 x n cell array that contains 3 x 1 matrices.
You have 3 values per element of t; how do you want them plotted? Do you want t on the x axis and three separate lines, one consisting of the first coordinates connected, one of the second, one of the third ?
Rashmil Dahanayake
编辑:Rashmil Dahanayake 2014-1-3
I think the correct definition should be odq(:,:,k) which is a 3 dimension matrix.
I need to plot. X axis: t values Y axis : 3 elements of dqo
(The output should look like subplot(2,1,1). run the attached m-code. I used manual method to save data instead of cell.)

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2014-1-3
plot(t, horzcat(odq{:}).' )

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by