Need help one multiple data exporting to xls

1 Ansicht (letzte 30 Tage)
Haolong Huang
Haolong Huang am 15 Mai 2019
Kommentiert: Haolong Huang am 16 Mai 2019
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'];

Akzeptierte Antwort

convert_to_metric
convert_to_metric am 15 Mai 2019
Bearbeitet: convert_to_metric am 15 Mai 2019
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 Kommentare
Guillaume
Guillaume am 15 Mai 2019
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 am 16 Mai 2019
Thank you so much for your answer, you solved my problem!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by