matrix multipication per elements and convert to char

hi, any solution with this matrix multipication??
pop =
9 0 -2 3 -4
8 -9 1 0 -3
7 -8 9 -1 2
6 -7 8 -9 1
if pop > 0,
m = [2*pop-1 2*pop; 2*pop 2*pop-1];
elseif pop == 0
m = [2*i+1 pop;2*i-1 pop]; % i is number of row's
elseif pop < 0,
m = [2*pop+1 2*pop; 2*pop 2*pop+1];
end
here's a resul's what i need:
17 18 2 0 -3 -4 5 6 -7 -8
18 17 1 0 -4 -3 6 5 -8 -7
15 16 -17 18 2 2 4 0 -5 -6
16 15 -18 -17 2 2 3 0 -6 -5
13 14 -16 -16 17 18 -2 -2 3 4
14 13 -16 -16 18 17 -2 -2 4 3
11 12 -14 -14 16 16 -17 -18 1 2
12 11 -14 -14 16 16 -18 -17 2 1
i appreciate a lot for any attention.. thx before

4 件のコメント

Friedrich
Friedrich 2012 年 3 月 7 日
If pop is really the matrix above, than none of the formulas for m will generate the matrix you want. Could you explain a bit more how the resulting matrix should be generated? So which laws should be applied on the input matrix?
In addition, your if else brance is never true at all, e.g. this will display never the word true:
if pop > 0
disp('true')
elseif pop == 0
disp('true')
elseif pop < 0
disp('true')
end
So what do you want achive exactly?
Jan
Jan 2012 年 3 月 7 日
There was a very similar question some days ago - it used "a" instead of "pop". But I cannot find it anymore. Has it been deleted to increase our confusion?
The operation should happen elementwise, so each element is replaced by [2*pop(i,j)-1, 2*pop(i,j); 2*pop(i,j), 2*pop(i,j)-1]
mashudi
mashudi 2012 年 3 月 7 日
no, i didn't.. it just delete while i try to delete doubled recent post's, since i got a new formula for my research so i need a new solutions..
here's the answer from andrei bobrov on my previous question
out = cell2mat(arrayfun(@(pop)[2*pop 2*pop; 2*pop 2*pop],pop,'un',0));
and
k = @(pop)[2*pop-1 2*pop; 2*pop 2*pop-1];
out = blockproc(pop,[1 1],@(block_struct)k(block_struct.data))
he answer for 3 solutions but the last one is lost.
pardon me, it makes confuse on you. .
mashudi
mashudi 2012 年 3 月 10 日
so far, this is the solutions i have
out = cell2mat(arrayfun(@(pop)[2*pop 2*pop; 2*pop 2*pop],pop,'un',0));
[row, col]= size(out);
for b= 1:row
for k= 1:col
if out(b,k) > 0
if mod((b + k),2)== 0
out(b,k)= out(b,k)-1;
end
elseif out(b,k) == 0 && mod(k ,2)== 1
if mod(b ,2)== 1
out(b,k)= b + 1;
else
out(b,k)= b - 1;
end
else
if mod((b + k),2)== 0 && out(b,k) < 0
out(b,k)= out(b,k)+1;
end
end
out2=[out -out];
end
end

回答 (0 件)

この質問は閉じられています。

質問済み:

2012 年 3 月 7 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by