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 comentarios

Friedrich
Friedrich el 7 de Mzo. de 2012
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 el 7 de Mzo. de 2012
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 el 7 de Mzo. de 2012
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 el 10 de Mzo. de 2012
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

Respuestas (0)

La pregunta está cerrada.

Preguntada:

el 7 de Mzo. de 2012

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by