Effacer les filtres
Effacer les filtres

How to use 1 column and all rows from a matrix in each iteration?

1 vue (au cours des 30 derniers jours)
M
M le 4 Mar 2022
Commenté : M le 4 Mar 2022
How to use 1 column and all rows from a matrix in each iteration?
For an example there is a matrix 'M' and its size 7*127 , I want to use in the first iteration the first column and all rows , in the second iteration , I want to use the 2nd column and all rows and so on ..

Réponse acceptée

Stephen23
Stephen23 le 4 Mar 2022
for k = 1:size(M,2)
M(:,k)
end

Plus de réponses (2)

Arif Hoq
Arif Hoq le 4 Mar 2022
Modifié(e) : Arif Hoq le 4 Mar 2022
A=randi(100,7,127); % genrating random matrix
C=cell(1,size(A,2));
for i=1:size(A,2)
C{i}=A(:,i);% in each iteration all rows and single column
end
output=[C{:}]
output = 7×127
23 23 1 25 24 50 5 6 4 59 37 3 42 91 34 89 3 29 68 82 57 17 53 99 49 14 24 20 45 7 16 95 58 57 3 13 57 92 94 32 13 54 48 9 55 42 46 6 91 41 12 75 45 20 68 24 63 33 5 74 27 13 59 86 94 6 25 66 65 60 18 38 70 51 30 25 88 50 12 98 31 55 1 28 62 36 32 88 14 59 19 51 47 37 82 83 69 11 18 23 60 12 74 12 38 20 44 43 53 22 43 15 56 93 52 15 45 44 5 22 81 33 45 42 78 60 87 46 66 97 71 61 79 58 11 10 83 38 51 35 32 60 23 6 98 59 42 69 6 31 63 72 55 18 66 2 38 77 64 11 30 50 76 33 40 35 59 59 56 36 3 23 41 38 57 100 26 11 14 68 34 92 91 34 23 46 40 35 50 35 3 11 71 64 34 15 93 99 91 65 59 98 80 10 64 94 11 53 60 4

Image Analyst
Image Analyst le 4 Mar 2022
No need to complicate things with cell arrays. Simply extract the column into a column vector that you can then use in whatever computations follow, like for example
for col = 1 : size(M, 2)
% Extract a single column into a new column vector variable.
thisColumn = M(:, col);
% Now use that variable somehow, like in a custom function
% ProcessSingleColumn() that you write.
% Save results into another array called someValue.
someValue(col) = ProcessSingleColumn(thisColumn);
end

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by