how to exract varying matrix data

5 views (last 30 days)
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.

Accepted Answer

Iain
Iain on 18 Jun 2013
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

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!