Need help one multiple data exporting to xls

1 次查看(过去 30 天)
Hi All,
I encountered some trouble in exporting and naming my data to .xls.
I'm trying to do two for loops in order to process my 30 data. I firstly remove NaN values and the use log10 to revalue them. However, for writetable code, there always shows errors.
I would very appreciate it if anyone can help me solve the bugs in my codes!
Thanks!
for time=1:6
for drug=1:5
x1 = reshape(p(drug,time,1:2,:),[],1);
y1 = reshape(N(drug,time,1:2,:),[],1);
z1 = reshape(A(drug,time,1:2,:),[],1);
X = [x1 y1 z1];
X(any(isnan(X),2),:) = [];
data_log=[log10(X(:,1)) log10(X(:,2)) log10(X(:,3))];
data_log_table=array2table(single_cell_log);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%problems for the following row
filename=['time_';num2str(time);'_drug_';num2str(drug_);'.xlsx'];
writetable(single_cell_log_table, filename)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in subsettry (line 11)
filename=['time_';num2str(time;'_drug_';num2str(drug_);'.xlsx'];

采纳的回答

convert_to_metric
convert_to_metric 2019-5-15
编辑:convert_to_metric 2019-5-15
Hi Haolong,
I see 2 issues on line 11. You should use commas instead of a semicolons so that you will horizontally concatenate the strings. Also, there might be a typo. Perhaps you meant num2str(drug) and not num2str(drug_). In other words, try changing:
filename=['time_';num2str(time);'_drug_';num2str(drug_);'.xlsx'];
to
filename=['time_',num2str(time),'_drug_',num2str(drug),'.xlsx'];
  2 个评论
Guillaume
Guillaume 2019-5-15
I'd recommend using sprintf to create your strings. In my opinion it's a lot clearer, and it avoids having to perform any kind of concatenation:
filename = sprintf('time_%d_drug_%d.xlsx', time, drug);
Haolong Huang
Haolong Huang 2019-5-16
Thank you so much for your answer, you solved my problem!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by