From: Matt Fig on
Why not simply:

Qwertsmall = MRAAsmall(:,WSRRsmall)
From: Andy on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i3eit8$957$1(a)fred.mathworks.com>...
> Why not simply:
>
> Qwertsmall = MRAAsmall(:,WSRRsmall)

Because I thought it was an accident of the small sample data that the values of MRAAsmall(1,:) are just the indices in order. Of course, if you know this is the case, your one line solution is much clearer than using ismember.
From: Matt Fig on
Perhaps I am mistaken, but I took the OP to mean, "How to vectorize this:"

Qwertsmall = zeros(size(MRAAsmall,1),length(WSRRsmall));
for ii = 1:length(WSRRsmall)
Qwertsmall(:,ii) = MRAAsmall(:,WSRRsmall(ii));
end
From: Neil Stewart on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i3el0o$s1i$1(a)fred.mathworks.com>...
> Perhaps I am mistaken, but I took the OP to mean, "How to vectorize this:"
>
> Qwertsmall = zeros(size(MRAAsmall,1),length(WSRRsmall));
> for ii = 1:length(WSRRsmall)
> Qwertsmall(:,ii) = MRAAsmall(:,WSRRsmall(ii));
> end

This is exactly what I meant. Cheers.

I'm already using the cade you suggested but as I'm converting a worksheet from another program (not Matlab) I'm comparing outputs at every step and they seem to disagree here. Must be something going wrong when exporting this bit of data from the other program.
Thanks for the help.
From: Andy on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i3el0o$s1i$1(a)fred.mathworks.com>...
> Perhaps I am mistaken, but I took the OP to mean, "How to vectorize this:"
>
> Qwertsmall = zeros(size(MRAAsmall,1),length(WSRRsmall));
> for ii = 1:length(WSRRsmall)
> Qwertsmall(:,ii) = MRAAsmall(:,WSRRsmall(ii));
> end

I thought he was trying to match the value of WSRRsmall(ii) to a value in the first row of MRAAsmall, and then pull that column. In any case, all three methods work. Obviously, the ismember way is the slowest. The loop is nearly as fast as the one-liner you posted before:


clear;
clc;
MRAAsmall = [1 2 3 4 5 6 7;2 4 6 8 10 12 14;3 6 9 12 15 18 21];
WSRRsmall = [1 5 6 6 3 2 7 1 1 4 3 2];
tic
Qwertsmall = MRAAsmall(:,WSRRsmall);
toc
tic
[tf,loc]=ismember(WSRRsmall,MRAAsmall(1,:));
Qwertsmall2 = MRAAsmall(:,loc);
toc
tic
Qwertsmall3 = zeros(size(MRAAsmall,1),length(WSRRsmall));
for ii = 1:length(WSRRsmall)
Qwertsmall3(:,ii) = MRAAsmall(:,WSRRsmall(ii));
end
toc
isequal(Qwertsmall,Qwertsmall2)
isequal(Qwertsmall2,Qwertsmall3)

% displays:
Elapsed time is 0.000012 seconds. % one-liner
Elapsed time is 0.002412 seconds. % ismember
Elapsed time is 0.000020 seconds. % loop
% all correct:
ans =
1
ans =
1