How can i visualize an exact column or row only of a matrix?
Afficher commentaires plus anciens
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
Plus de réponses (1)
Walter Roberson
le 22 Juil 2017
plot( YourMatrix(:,29) )
16 commentaires
Elias Unk
le 22 Juil 2017
James Tursa
le 22 Juil 2017
try FileData.B(:,29)
Walter Roberson
le 22 Juil 2017
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.
Elias Unk
le 22 Juil 2017
Walter Roberson
le 22 Juil 2017
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
Elias Unk
le 22 Juil 2017
Walter Roberson
le 22 Juil 2017
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?
Image Analyst
le 22 Juil 2017
After you READ THIS LINK then attach your .mat file so we can stop this long-lasting, fruitless guessing game.
Elias Unk
le 22 Juil 2017
Walter Roberson
le 23 Juil 2017
storedStructure = load('features.mat')
myMatrix = vertcat(storedStructure.B{:});
col29 = myMatrix(:,29);
plot(col29)
Image Analyst
le 23 Juil 2017
% 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]);

Elias Unk
le 23 Juil 2017
Elias Unk
le 23 Juil 2017
Walter Roberson
le 23 Juil 2017
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)
Image Analyst
le 23 Juil 2017
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.
Elias Unk
le 23 Juil 2017
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!