Summing in Matlab using data extracted from Excel
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi Matlab wizards. I'm new to Matlab, and can use some assistance in the following query. I'm extracting certain cells of numerical data into Matlab and want to perform a summation over them. Below is an example of the data in extracting:
%Cash
A1 = xlsread(filename,2,C8)
%Retail Mortgage
A2 = xlsread(filename,2,C9)
%Loans
A3 = xlsread(filename,2,C10)
%Other Recievables
A4 = xlsread(filename,2,C11)
%Govt. Bonds
A5 = xlsread(filename,2,C12)
%Corp. Bonds
A6 = xlsread(filename,2,C13)
I ideally want to perform a summation over the A_i for 1 <= i <= 6, but am struggling a bit on how I go about this. Can anyone offer a bit of help please? Thank you!
1 Comment
Guillaume
on 9 Jul 2018
Never number variables. If you start numbering variables, it's a clear indication that a container of some sort would be much better. In your case an array:
A(1) = xlsread(...
A(2) = ...
etc.
Then the summation is trivial:
sum(A)
However, as per dpb answer, even simpler is to read the whole array at once.
Answers (1)
dpb
on 9 Jul 2018
vals=xlsread(filename,2,'C8:C13');
total=sum(vals);
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!