A question about a special output
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mojtaba Mohareri
le 25 Nov 2019
Commenté : Mojtaba Mohareri
le 26 Nov 2019
I've used random function rand(2,2) for my problem. The output is a matrix 2*2 of numbers somwthing like this: the first row: 1 2 and the second row: 5 6. How can I have my output to be like this {{1,2},{5,6}}? and how can I save it in a notepad?
Thanks in advance.
0 commentaires
Réponse acceptée
Image Analyst
le 25 Nov 2019
Try this:
fullFileName = fullfile(pwd, 'Mojtaba.txt')
% Open a text file.
fileHandle = fopen(fullFileName, 'wt');
% Write out the things we want to write out.
fprintf(fileHandle, '1 2\n5 6\n');
% Close the file.
fclose(fileHandle);
% Open it in notepad (Windows OS only)
winopen(fullFileName);
3 commentaires
Image Analyst
le 26 Nov 2019
data = rand(1000, 2)
fprintf(fileHandle, '%f, %f\n', data'); % The transpose (apostrophe) is important! Don't omit it or the data will be transposed in the file.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!