save thw values of four variable in a file
Afficher commentaires plus anciens
Hi
i want to save four variable from a matlab code in a file ( like xls)
the two from four value have many values (10000)
thank
George
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 20 Mai 2023
0 votes
If you do not need headers, put them in a vector and writematrix.
If you need headers create a table() and writetable
7 commentaires
george veropoulos
le 20 Mai 2023
Modifié(e) : Walter Roberson
le 20 Mai 2023
Walter Roberson
le 20 Mai 2023
It is a bit tricky to get xls files that have different numbers of rows for each variable. You can writetable() one at a time specifying 'Range' to indicate where in the file the results should go. Or you can put all of the values into a cell (including the headers as the first row) with empty cells for the places with no values, and then writecell() . Or you can pad the shorter variables with NaN: NaN show up as empty when you view xls files.
george veropoulos
le 20 Mai 2023
Walter Roberson
le 21 Mai 2023
%build cell to hold values. We count on automatic extension of the cell
%array if some of the rows are longer than what already exists
overcell = num2cell(Z12(:));
overcell(1:numel(Y),2) = num2cell(Y(:));
overcell(1:numel(bin),3) = num2cell(bin(:));
overcell(1:numel(values),4) = num2cell(values(:));
%insert header
overcell = [{'Z12 (V/mm)', 'Y (Ohm/Hz)', 'bin (F/J)', 'values (furlong/fortnite)'};
overcell];
%write it out
writecell(overcell, 'FileNameGoesHere.xls');
george veropoulos
le 21 Mai 2023
george veropoulos
le 21 Mai 2023
Walter Roberson
le 21 Mai 2023
There are limits on the number of rows for xls files. There are higher limits for xlsx files, a little over 1 million rows.
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!