Pdata = reshape(pressureData(1,1,:),1,[]) plot(t,Pdata)
Dimensionality error with plot
1 次查看(过去 30 天)
显示 更早的评论
Hi, I would like to plot a snippet of pressureData, which is a 3 dimensional matrix, as follows:
tDim=length(pressureData(1,1,:)); t=zeros(1,tDim); dt=0.01;
for ii=1:tDim % Build time axis for plot
t(ii)=ii*dt;
end
plot(t,pressureData(1,1,:))
This returns an error saying "Error using plot. Data cannot have more than two dimensions."
When I output the vector pressureData(1,1,:) in the command window, the output looks like this:
ans(:,:,1) =
-0.0038
ans(:,:,2) =
-0.0042
etc.
The data type for pressureData is double, so I'm not sure why I am getting this odd output. Any ideas? Thanks in advance!
5 个评论
the cyclist
2023-6-20
Neither of the solutions so far (as I write this) change the size of pressureData.
采纳的回答
the cyclist
2023-6-20
编辑:the cyclist
2023-6-20
I understand your confusion. pressureData(1,1,:) is a vector in the sense that it only has elements along one dimension (the 3rd dimension), but it is still a three-dimensional MATLAB array because it is 1x1xtDim.
There are a couple possible solutions. Probably the easiest is to use the squeeze function to remove the dimensions that have length 1.
plot(t,squeeze(pressureData(1,1,:)))
3 个评论
the cyclist
2023-6-20
编辑:the cyclist
2023-6-20
The size of pressureData doesn't really matter. The fact remains that
pressureData(1,1,:)
is a 1x1x5000 array, which is 3-dimensional. MATLAB will not treat that as a vector for plotting purposes, which is why you get the error. But
squeeze(pressureData(1,1,:))
is a 5000x1 vector, which will plot.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!