Renaming a Excel file from an array

3 ビュー (過去 30 日間)
Sugar Mummy
Sugar Mummy 2022 年 1 月 22 日
コメント済み: Sugar Mummy 2022 年 1 月 23 日
Hello everyone!
I am facing problem in renaming my Excel file. I have a defined variable with values (5x1 double)
values=[0.0082;0.0083;0.0086;0.0087;0.0082];
There is a matfile (test.mat) which have values of variables (a,b and c)
All_values=values;
for i =1:numel(All_values)
values=All_values(i)
T = table(a{1,i}.time, oo{1,i}.signals.values, pp{1,i}.signals.values) %values from .mat file
writetable(T{i},'Check_%i.xlsx',values) %somewhere here is the issue
end
What I want is to rename my file like 0.0082.xlsx, then comes 0.0083.xlsx, 0.0086.xlsx, 0.0087.xlsx and 0.0082.xlsx. The code is running fine till the values of T (making a table). Any help to rename the file would be highly appreciated. Thanks!
  6 件のコメント
Stephen23
Stephen23 2022 年 1 月 22 日
Your WRITETABLE call does not follow any syntax shown in the documentation.
It looks you are attempting to create a filename using values, in which case you need to use SPRINTF:
F = sprintf('Check_%i.xlsx',values);
writetable(T,F)
Sugar Mummy
Sugar Mummy 2022 年 1 月 23 日
@Stephen thanks alot! this worked for me

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

回答 (1 件)

KSSV
KSSV 2022 年 1 月 22 日
All_values=values;
for i =1:numel(All_values)
values=All_values(i)
T = table(a{1,i}.time, oo{1,i}.signals.values, pp{1,i}.signals.values) %values from .mat file
fname = ['Check_',num2str(i),'xlsx'] ;
writetable(T{i},fname,values)
end
  1 件のコメント
Sugar Mummy
Sugar Mummy 2022 年 1 月 22 日
Hi, thank you for the response Sir but it gives the following error
PS: I am using MATLAB 2019a

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

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by