How can I use xlswrite in a for loop without overwriting?

1 回表示 (過去 30 日間)
Marina Gil
Marina Gil 2018 年 5 月 28 日
コメント済み: Prinson Chandy 2018 年 8 月 22 日
I'm trying to generate 31 excel files with a for loop:
days=31;
for i = 1:1:days
dataday = frequency(1,((i-1)*(size(frequency,2)/days)+1):(size(frequency,2)/days)*i);
xlswrite('frequency.xlsx',dataday');
end
Why I can not obtain 31 Excel files? Thanks in Advance!
  6 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 5 月 28 日
編集済み: Ameer Hamza 2018 年 5 月 28 日
@Paolo consider adding your comment as an answer and @Marina please accept it, as it will help in marking this question as solved.
Paolo
Paolo 2018 年 5 月 28 日
@Marina You are welcome, happy to help. I wrote an answer for the question. As @Ameer pointed out, selecting the answer as accepted will mark the question as solved and will help other users in the future.

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

採用された回答

Paolo
Paolo 2018 年 5 月 28 日
If you wish to create a new Excel file for every iteration of the loop, you can use:
xlswrite(strcat('frequency',num2str(i)),dataday');
The term 'frequency' is concatenated with the iteration number.
The data for every iteration will be written to the first sheet of every file. The files will be saved in the current directory and will be named:
'frequency1.xls','frequency2.xls' ... 'frequency31.xls'

その他の回答 (2 件)

Roozbeh Yousefnejad
Roozbeh Yousefnejad 2018 年 5 月 28 日
I believe you can add "i" to xlswrite('frequency.xlsx',dataday') like xlswrite('frequency.xlsx',dataday',i) to change the excel sheet everytime, so at the end you will end up with one excel file and in each sheet you have your data
  1 件のコメント
Paolo
Paolo 2018 年 5 月 28 日
She specified she requires data in different files, not different sheets.

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


Prinson Chandy
Prinson Chandy 2018 年 8 月 20 日
Question: what we have to do when we need to crate notepad file instead of excel file
  2 件のコメント
Paolo
Paolo 2018 年 8 月 20 日
Do you mean a text file? You can apply the same logic but obviously can't use xlswrite as you are not working with an Excel spreadsheet. What's the format of your data?
Prinson Chandy
Prinson Chandy 2018 年 8 月 22 日
for each iteration of for loop, i need to write matrix in .txt file

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

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by