how to exract varying matrix data

1 visualizzazione (ultimi 30 giorni)
Ede gerlderlands
Ede gerlderlands il 18 Giu 2013
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.

Risposta accettata

Iain
Iain il 18 Giu 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

Più risposte (0)

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by