Summing in Matlab using data extracted from Excel
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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
Guillaume
2018년 7월 9일
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.
답변 (1개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!