Simple mathematics giving unexpected outcome. Dividing data arrays/vectors
Show older comments
I am trying to do some calculations, but there are giving me really strange results. And I am not sure where to start looking for a solution.
I have a very simple calculation: Divide each element in the first row (or column) by the corresponding element in the second row (or column).
My input is attached;
bands 71X2 double
and I would like to get the 71 values that you get when you divide bands(:,1) by bands(2,:).
I tried this:
%original data, to ensure the right output, transpose the data:
spectralindex = bands(:,1)' ./ bands(:,2)' ;
%Or transpose the data first:
bands2 = bands';
spectralindex2 = bands2(1,:) ./ bands2(2,:) ;
%or create separate variables
band1 = bands(:,1)';
band2 = bands(:,2)';
spectralindex3 = band1 ./ band2;
Looking at the data:
bands(1,1) = 0.0709 & bands(1,2) = 0.0275. If I take a calculator and divide these, I get 0.0709 / 0.0275 = 2.578. This is the outcome I am expecting to get from matlab too. A regular division of value 1 by value 2.
However the matlab outcome shows 2.5803 as outcome.
There probably is something very logical about this, with me making a conceptual mistake on how these calculations are done. But.. I cannot figure out what. Slightly baffled. Does anyone have an idea of what is going on?
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!