フィルターのクリア

writing output in excel file with variable to decide starting cell to write data

2 ビュー (過去 30 日間)
Prasad Raut
Prasad Raut 2019 年 3 月 19 日
コメント済み: Prasad Raut 2019 年 3 月 19 日
Hi,
I have done 100 test runs and for each run I have processed and averaged data(single value) for 20 different signals. I have to run matlab code to process the data
after each code run I get a set of 20 values for that particular test run. I wanted to write them in single excel file.
Currently I am able to write xlswrite command to output test run data of particular test (whichever I am running matlab code for) in excel format but if I run code next time again it will overlap my previous data in excel file
Can someone explain me how can I use xlswrite command with a variable
for example
this is the command I use to have excel output
xlswrite (filename,Output,sheetname,'B2');
if there is way to assign variable (instead of 'B2' which is a constant) to decide where to start printing data in excel , I believe that will resolve my querry.

採用された回答

dpb
dpb 2019 年 3 月 19 日
編集済み: dpb 2019 年 3 月 19 日
Sure, just use my little utility xlsAddr to build the address and pass to xlswrite
for i=1:N
output=yourfunction(data(:,i));
xlswrite('Output.xlsx',output,xlsAddr(2,i+1)) % write to column B2, C2, ...
end
function rnge=xlsAddr(row,col)
% Build Excel cell address from row, column
%
% RNGE=XLSADDR(ROW,COL) will return an Excel cell address
% formed from the input ROW,COL values. Either input may be
% string or numeric and will be converted to canonical form
if isnumeric(col)
if ~isscalar(col), error('Input Column Not Scalar'), end
rnge=num2str('A'+[fix(col/26) rem(col,26)]-1,'$%c%c');
rnge(rnge=='@')=[]; % cleanup for single character
else
rnge=['$' col];
end
if isnumeric(row)
if ~isscalar(row), error('Input Row Not Scalar'), end
rnge=[rnge num2str(row,'$%d')];
else
row=num2str(row,'$%d');
if ~all(ismember(row,'0':'9')), error('Invalid Excel Address: Row not numeric'), end
rnge=[rnge row];
end
I'm not sure, later releases of Matlab may have similar functions; at the time I wrote this there weren't any supplied excepting in some private supporting routines...
Alternatively, save your data into an array by similarly allocating room for each new vector in a column of an array and then wait and write the whole shebang at once. Unless you have zillions of these, memory should be no issue.
  1 件のコメント
Prasad Raut
Prasad Raut 2019 年 3 月 19 日
Ok sure I will try both the methods. Thank you very much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by