how to exract varying matrix data

1 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by