extract the same coloumn from multiple mtrix

Hi! I'm new here i want to ask if there is a solution in Matlab to extract the same column number from multiple matrix. I have 640 matrix and I want to extract from each mtrix the column indexed 70 and save this column in one new matrix .I thank you in advance for your help

 採用された回答

Matt J
Matt J 2012 年 10 月 19 日
編集済み: Matt J 2012 年 10 月 19 日

1 投票

If your data exists as an MxNx640 array, then it's easy
newmatrix= data(:,70,:);
newmatrix=reshape(newmatrix,M,640);

5 件のコメント

sami
sami 2012 年 10 月 19 日
thank you how can create a MxNx640 array from 640 matrices ?
Matt J
Matt J 2012 年 10 月 19 日
We need to know more about the form of your data and how they got that way.
Do you have 640 separate matrix variables in your workspace? If so, how did you create them?
Are the matrices in a cell array A{1}, A{2},...A{640}? If the latter, you can just do
M=cat(3,A{:})
sami
sami 2012 年 10 月 19 日
the 640 matrices are 150*19 Double matrices and are named device1_1 to device1_80 device2_2 to device2_80 and so on 8 times
Matt J
Matt J 2012 年 10 月 19 日
Sigh... Well, first we'll have to undo the damage. Nothing will be fast until we do:
M=cell(8, 80);
for i=1:8
for j=1:80
M{i,j}=eval(['device' num2str(i) '_' num2str(j)]);
end
end
Now you can do as before
data=cat3(M{:});
newmatrix= data(:,70,:);
newmatrix=reshape(newmatrix,M,640);
sami
sami 2012 年 10 月 19 日
Thank you

サインインしてコメントする。

その他の回答 (2 件)

Razvan
Razvan 2012 年 10 月 19 日

0 投票

To extract column 70 from matrix M you do
C = M(:,70);
To add this column to another matrix (M2) you do
M2 = [M2, C];

3 件のコメント

sami
sami 2012 年 10 月 19 日
thank you for your response. I now that but I won't do it manually 640 times. there is no faster solution ?
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 19 日
編集済み: Azzi Abdelmalek 2012 年 10 月 19 日
how are named your 640 matrix? , or do you import them each iteration
sami
sami 2012 年 10 月 19 日
the 640 matrices are 150*19 Double matrices and are named device1_1 to device1_80 device2_2 to device2_80 and so on 8 times

サインインしてコメントする。

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 19 日
編集済み: Azzi Abdelmalek 2012 年 10 月 19 日

0 投票

M=[]
for k=1:8
s=['M=[M' sprintf([',device%d_%d(:,70)'],[k*ones(1,80);(1:80)]) ']']
eval(s)
end

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2012 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by