How can i visualize an exact column or row only of a matrix?

let's say i have a 50 by 70 matrix and i want all the values of the column number 29, how can i do that.

 Réponse acceptée

Extract from .mat file, then call plot. Try this:
storedStructure = load('features.mat');
myMatrix = storedStructure.B; % Extract matrix from the "B" field of the structure.
plot(myMatrix(:,29), 'b-', 'LineWidth', 2);

2 commentaires

Elias Unk
Elias Unk le 22 Juil 2017
Modifié(e) : Walter Roberson le 22 Juil 2017
i did get the following error:
Error using plot
Invalid first data argument
Please attach your .mat file (third request).

Connectez-vous pour commenter.

Plus de réponses (1)

plot( YourMatrix(:,29) )

16 commentaires

so it didn't work, my actual code:
FileData = load('features.mat');
openvar('FileData.B');
how to adjust it?
try FileData.B(:,29)
There is no way to openvar only a particular field of a structure. You would need to assign the field to a variable and then open the variable.
Didn't work James i got this [1x116 double] keep in mind 50x70 are not my actual matrix size. Can you guide code wise walter?
You have a struct. It is not clear if it is a scalar struct or a struct array. If you have a struct array 50 x 70 containing a field "B" and you want to retrieve column 29 of all members of that struct array, then
B29 = reshape( arrayfun(@(IDX) FileData(IDX).B(:,29), 1:numel(FileData), 'uniform', 0), size(FileData) );
This would be a cell array 50 x 70, each element of which would be a column vector, with the various column vectors not necessarily being the same size as each other.
Provided that the various B are indeed all the same size, you might potentially want to proceed from there to
temp = cellfun( @(M) reshape(M, 1, 1, []), B29, 'uniform', 0);
M29 = cat(3, temp{:});
The result would be 50 x 70 x (whatever) such as 50 x 70 x 116
"Visualizing" this could be a bit tricky. You might want to consider slice() or isosurface(); or as of R2017a, volumeViewer
... but perhaps I am misinterpreting the question, getting confused by the 50, 70, and 116
walter it's not a 3D shape it's a 2 D but the dimentions aren't exactly 50 70 i just gave that as an example at first
Have you ever considered the benefits of describing your data type clearly, perhaps even attaching some sample data, and describing the output you would like to see?
After you READ THIS LINK then attach your .mat file so we can stop this long-lasting, fruitless guessing game.
  • 1 2 3 4
  • 5 6 7 8
  • 9 4 3 2
  • 1 3 4 6
the expected outcome would be : 3 7 3 4 if i want column 3 only.Kindly note the values are type double and in a .mat database
storedStructure = load('features.mat')
myMatrix = vertcat(storedStructure.B{:});
col29 = myMatrix(:,29);
plot(col29)
% Plot the 116 element vector.
plot(col29, 'b*-', 'LineWidth', 2);
grid on;
fontSize = 25;
title('Plot of B, column 29', 'FontSize', fontSize);
xlabel('Index', 'FontSize', fontSize);
ylabel('B Value', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
Thanks image it worked
Now what changes will i have to do to see line 29 instead of column 29
storedStructure = load('features.mat')
myMatrix = vertcat(storedStructure.B{:});
row29 = myMatrix(29,:);
plot(row29)
However, since the elements are row vectors, this would be equivalent to
storedStructure = load('features.mat')
row29 = storedStructure.B{29};
plot(row29)
Just to expand on this for something you might want to know about some day, if you use
storedStructure = load('features.mat')
it reads in all the variables you stored as fields of storedStructure. So if you have stored A, B, and C, you'd have storedStructure.A, storedStructure.B, and storedStructure.C. Now if you wanted to pull out just one of those (which probably won't make any speed difference unless they were huge), you could ask load() to load just one from the file. For example:
storedStructure = load('features.mat', 'B');
Now storedStructure will have only a B field, not an A and C field. You could also extract the variable into its own B variable, if you want, like this:
B = storedStructure.B;
Just an FYI.
Cheers Walter,very helpful

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by