Putting columns from an array into evenly spaced columns in excel

1 回表示 (過去 30 日間)
Robert Roy
Robert Roy 2016 年 5 月 7 日
コメント済み: Robert Roy 2016 年 5 月 7 日
Hi there, Currently I am trying to come up with can easier code to allow me to put Tresult into evenly spaced columns and then another code which put a label to the left for each of these columns. Ive got wat I need slighlty below but I am wondering if there is a way to make this alot simpler? Cheer
if true
% code
end
for j=1:10
for l=1:10
Tresult(:,j)=mean(Cr).';
end
filename1='hProfile';
Sheet=1;
end
xlswrite(filename1,Tresult(:,1),Sheet,'C1');
xlswrite(filename1,Tresult(:,2),Sheet,'E1');
xlswrite(filename1,Tresult(:,3),Sheet,'G1');
xlswrite(filename1,Tresult(:,4),Sheet,'I1');
xlswrite(filename1,Tresult(:,4),Sheet,'K1');
xlswrite(filename1,Tresult(:,6),Sheet,'M1');
xlswrite(filename1,Tresult(:,7),Sheet,'O1');
xlswrite(filename1,Tresult(:,8),Sheet,'Q1');
xlswrite(filename1,Tresult(:,9),Sheet,'S1');
xlswrite(filename1,Tresult(:,10),Sheet,'U1');

採用された回答

Ced
Ced 2016 年 5 月 7 日
編集済み: Ced 2016 年 5 月 7 日
Hi
You could always write it in a loop, e.g. using the char-int conversion.
As an alternative: instead of writing a matrix, you can write a cell array. This allows you to leave certain cells and columns empty. Here is an example:
Tresult = randn(5,10);
% write settings
filename1 = 'hProfile';
start_cell = 'C1'; % starting cell
Sheet = 1; % sheet number
skip_col = 1; % number of empty columns between entries
% transform into cell and insert empty columns
Nrows = size(Tresult,1);
Ncols = size(Tresult,2);
Tresult_cell = cell(Nrows,(1+skip_col)*Ncols);
Tresult_cell(:,1:(1+skip_col):end) = num2cell(Tresult);
% write file
xlswrite(filename1,Tresult_cell,Sheet,start_cell);
! Note that this will overwrite whatever was in your excel file before, i.e. the "empty" cells will also be written, but they will just be empty.
Cheers

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 5 月 7 日
You could get rid of the unneeded loop over the badly-named "l". Or get rid of both loops altogether since Tresult(:,j) and mean(Cr).' don't ever change values in the loop - it's always the same scalar mean(Cr).' which can be computed outside any loops.
  1 件のコメント
Robert Roy
Robert Roy 2016 年 5 月 7 日
Apologies sorry, Cr does have an l in it, i took it out sorry because it was quite long and complicated equation

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

カテゴリ

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