plotting a single vector out of a multidimensional array?

4 views (last 30 days)
Hi,
I've got an M-file that calculates error data and stores it in a multidimensional array. 1st Dimension determines which dataset I refer to, 2nd dimension determines which sensor in a multi-sensor array the measurements are from, and the 3rd dimension is finally the calculated error at each point of the original signal.
I'm thus just using a multi-dimensional array as a way to store all of the error vectors in a single structure. But, when I try to plot a single error vector at given index values for the 1st and 2nd dimensions using the plot command, I get matlab errors:
>>plot(Xhat(1,3,:));
"Error using plot Data may not have more than 2 dimensions"
Why won't that work? I've specified a 1-dimensional set of data for it to plot, but it won't do it? How should I approach this differently?

Accepted Answer

Cedric
Cedric on 9 Apr 2013
Edited: Cedric on 9 Apr 2013
You have two singleton dimensions when you index Xhat(1,3,:). Look at the following:
>> A = rand(2,3,4) ;
>> v = A(1,2,:)
v(:,:,1) =
0.4168
v(:,:,2) =
0.9841
v(:,:,3) =
0.3395
v(:,:,4) =
0.4228
>> size(v)
ans =
1 1 4
>> v = squeeze(A(1,2,:))
v =
0.4168
0.9841
0.3395
0.4228
>> size(v)
ans =
4 1
If you don't index across datasets too often, I would recommend switching your dimensions, e.g having sensor x point x dataset. This would simplify the indexing and make it (much) more efficient if you have large datasets.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!