how to exract varying matrix data

2 ビュー (過去 30 日間)
Ede gerlderlands
Ede gerlderlands 2013 年 6 月 18 日
I have a file X=(20,350) and i want to select the column value using a selecting a selcting matrix y= (1,350)
for i= 1:350
p(y(i),:)= X(1:y(i),:)
end
but couldn't solve the problem . any help in this regard is highly appreciated.

採用された回答

Iain
Iain 2013 年 6 月 18 日
p(y(i),:)= X(1:y(i),:)
Is trying to put a y(i) by "n" matrix into a 1 by "n" matrix, which CANNOT work.
p(y(i),:)= X(y(i),:)
Is trying to put a 1 by "n" matrix into a 1 by "n" matrix, which can work, provided that "y" has enough elements.
If you define y to be a list of the ROWS you want (this is the way round you've got your code, swap the :, and y(i) round for columns):
p = zeros(size(X)); % or ones, or NaNs, or whatever else as needed.
y = [1 5 7 8 9 350];
for i = 1:numel(y)
p(y(i),:) = X(y(i),:);
end
  1 件のコメント
Ede gerlderlands
Ede gerlderlands 2013 年 6 月 18 日
thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by