Effacer les filtres
Effacer les filtres

Need help one multiple data exporting to xls

2 vues (au cours des 30 derniers jours)
Haolong Huang
Haolong Huang le 15 Mai 2019
Commenté : Haolong Huang le 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'];

Réponse acceptée

convert_to_metric
convert_to_metric le 15 Mai 2019
Modifié(e) : convert_to_metric le 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 commentaires
Guillaume
Guillaume le 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 le 16 Mai 2019
Thank you so much for your answer, you solved my problem!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by