Need help one multiple data exporting to xls

조회 수: 1 (최근 30일)
Haolong Huang
Haolong Huang 2019년 5월 15일
댓글: Haolong Huang 2019년 5월 16일
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