multiplication of equevalant element of three cells by a predetermined vector

5 次查看(过去 30 天)
Hi all; I've written a program including some cells like below:
clc; clear;
s=[ 0 10 20 30];
pr=[0.24 0.40 0.36];
f=[625 425 425; 125 125 125; 25 25 25; 125 125 125];
sm=[30 20 10 0;-10 30 20 10;-10 -10 30 20];
for n=1:10
fmin_init{n}=f;
for t=1:3
for ss=1:4
s2{t,ss}= sm,
for qq=1:3
tsd_intrpln{n,qq}=interp1(s(:),fmin_init{n}(:,qq), s2{t,ss});
end
% my problem is here >> tsd{n,ss}= Pr.* tsd_intrpln{n,:}
end
end
end
I want to multiply each element of matrix "pr" i.e. [0.24 0.40 0.36] respectively by each element of matrix "tsd_intrpln{n,1}" and its equevalant element in "tsd_intrpln{n,2}" and also "tsd_intrpln{n,3}" for example:
-the first element of "tsd_intrpln{n,1}" is multiplied by "pr(1) " . i.e. a11* 0.24
-the first element of "tsd_intrpln{n,2}" is multiplied by "pr(2) " . i.e. a'11* 0.4
-the first element of "tsd_intrpln{n,3}" is multiplied by "pr(3) " . i.e. a''11* 0.36 .
How can I do this. I look forward to reply.m

回答(1 个)

Geoff
Geoff 2012-4-4
I seem to give a lot of answers that use arrayfun, and I don't want to be cliché, but it seems you need it here to pull out the element from each matrix.
tsd{n,ss} = pr .* arrayfun(@(x) tsd_intrpln{n,x}(1,1), 1:3);

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by