Summing in Matlab using data extracted from Excel
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
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 Commento
Guillaume
il 9 Lug 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.
Risposte (1)
dpb
il 9 Lug 2018
vals=xlsread(filename,2,'C8:C13');
total=sum(vals);
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!