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
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 ?
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!