How adding multiples values insiade Excel file ?

1 回表示 (過去 30 日間)
Furat Alobaidy
Furat Alobaidy 2020 年 2 月 8 日
回答済み: Furat Alobaidy 2020 年 2 月 8 日
hi , i have multi excel files contains multiple values, i need adding the values for each variable which is repeated much time inside the Excel file as in the code below, Please
the variable: sim_ticks have multi vales inside the Excel file , i need adding all these values together !
xlfiles = dir('*.xlsx'); % You are in the folder of xl files
Nfiles = length(xlfiles) ; % number of xl files
% loop for each file
for i = 1:Nfiles
fname = xlfiles(i).name ; % file name
[~,~,dat] = xlsread(fname) ; % read the file
p= strcmp(dat(:,1),'sim_ticks') ; %# 1- Find the value of sim_ticks
simtickx(i) = sum( cell2mat(dat(p,2)); % this summing values gave me error !!!
ca{i, 1} = simtickx(i);
end
col_header={'Total Ticks'}; %Row cell array (for column labels)
xlswrite('SRAMBLACkholes.xlsx',col_header,'Sheet1','A1'); %Write column header
cellReference = sprintf('A2');
xlswrite('SRAMBLACkholes.xlsx', ca, 'Sheet1', cellReference); % Write out ca, not data.
Error: File: test1.m Line: 11 Column: 51
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.

採用された回答

Furat Alobaidy
Furat Alobaidy 2020 年 2 月 8 日
thanks a lot for your help.

その他の回答 (1 件)

BN
BN 2020 年 2 月 8 日
編集済み: BN 2020 年 2 月 8 日
Hello
Look at this line of your code:
simtickx(i) = sum( cell2mat(dat(p,2)); % one ) is missed
You don't close a parenthesis ), so :
simtickx(i) = sum( cell2mat(dat(p,2))); % fixed
Further than this, I recommend you to use writetable instead of xlswrite.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by