scalar matrix operations / vector arithemtics
Ältere Kommentare anzeigen
Hello!
I have a problem when I want to calculate percentage deviations from values. Ie. I have the following vecotrs:
a = [-3.67843750000000;
-0.149062500000000;
-0.0284375000000000;
1.52562500000000;
0.217812500000000;
0.00562500000000000;
-0.00625000000000000;
-0.00875000000000000;
-0.00750000000000000;
-0.00937500000000000;
-0.00937500000000000;
-0.00937500000000000]
b = [-5;
-0.0116649326387481;
-2.72141306933060e-05;
4.98833506736125;
0.255995664691759;
0.0123648464061628;
0.000597234436888179;
2.88470200832711e-05;
1.39333989516825e-06;
6.72997092199941e-08;
3.25064320400358e-09;
1.57009314931713e-10]
When I want to see on how much percentage each element in vector a differs from the same index element in vector b, i thought I can do this with a for loop:
for i=1:1:length(a)
deviation(i,1) = (a(i,1) - b(i,1))*100/b(i,1);
end
deviation
but as you can see the result is wrong, or I have formated it wrong.
I then thought ok, maybe i can do it with scalar multiplication and division:
deviation_scalar = (a - b)*100./b
but this is also not returning the correct result. I.e. for the first entry the calculation would be:
(-3.6784 - -5)*100/-5
which gives me now the correct result. But i don't understand what I do wrong with the vector arithmetic. Does anyone have a clue?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
