To extract the random integer into a file
1 次查看(过去 30 天)
显示 更早的评论
HEllo guys,
am new to this matlab, my Q is probably very simple for you guys.please help me. I want to extract the random integer from the script
data = randint(1,48,2) to a new file so that the same data can be called for and use for the next iteration. someone can help me please.
0 个评论
采纳的回答
Chandra Kurniawan
2011-12-27
If you get a little confused with fread and fwrite, then
you can try another command fprintf n fscanf
Here I give you sample code :
Let say you want to store 'data = randint(1,48,2)' into txt file.
data = randint(1,48,2)
fid = fopen('data01.txt', 'w');
fprintf(fid,'%d ',data);
fclose(fid);
And for recalling this data later, you can read from the text file you have created
fid = fopen('data01.txt');
m5 = fscanf(fid,'%d')'
fclose(fid);
Ask me again if it still difficult to understand.
更多回答(3 个)
Chandra Kurniawan
2011-12-27
You can use fwrite command to write array into binary file.
And you can use fread to read data from binary file
fiteri razali
2011-12-27
2 个评论
Walter Roberson
2011-12-27
"count = fprintf(...) returns the number of bytes that fprintf writes."
"status = fclose(...) returns a status of 0 when the close operation is successful. Otherwise, it returns -1."
There are situations where knowing the count or status is important, but your situation is not one of them.
Friedrich
2011-12-27
Hi,
when you want to use the data back in MATLAB again, the best would be a mat file, since it pretty easy:
data = randint(1,48,2)
save('filename.mat','data')
load('filename.mat')
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!