MATLAB: Subtracting two matrices yields a scalar in MATLAB

mathsubtraction

Dear all,
I have the following code :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:length(QRS_onset)
T_wave_duration_in_sec(i)=ST_Interval_in_sec(i)-ST_Segment_in_sec(i);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Both the ST interval and ST segment are matrices. However, the result of T wave duration is scalar. Why is this?
Thanks in advance for the help

Best Answer

Are you trying to only substract some of the elements? Else you can simply do: A-B. Also i guess you mean the result is a vector instead of a matrix. That is because of the way you fill it. You use linear indices for ST_Interval_in_sec and since T_wave_duration_in_sec is not predefined it just makes a vector. See: http://www.mathworks.nl/company/newsletters/articles/matrix-indexing-in-matlab.html
You can fix this by doing this before the loop: T_wave_duration_in_sec = zeros(rows,cols);
rows and cols should be the size of the output matrix.