フィルターのクリア

how to use "save" matlab

1 回表示 (過去 30 日間)
Daniel Barzegar
Daniel Barzegar 2014 年 6 月 19 日
編集済み: dpb 2014 年 6 月 19 日
Hi all, i create a very big file in matlab and then i try to write it in a txt file using the fprintf() function. But after a while a message pops up saying that there is not enough memory or sth like that.. How can i save it in the txt file? Can i use the save function of matlab to do that?
thanks. Daniel
  12 件のコメント
Daniel Barzegar
Daniel Barzegar 2014 年 6 月 19 日
i looked at the Workspace window and it seems that only the tAcc has values in it. The other 4 are empty (the same happens for the res_t*.data). any ideas why is that happening?
dpb
dpb 2014 年 6 月 19 日
The other files don't exist or are somewhere else, maybe? Hard to say from here, you'll have to poke around at the command line and see what's what...

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

採用された回答

dpb
dpb 2014 年 6 月 19 日
編集済み: dpb 2014 年 6 月 19 日
for i=1:size(res_tAcc.data,1)
fprintf(fid, '%f ', res_tAcc.time(i,1));
fprintf(fid, '%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f', ...
res_tAcc.data(i,1)', res_tAcc.data(i,2)', res_tAcc.data(i,3)', ...
res_tGyro.data(i,1)', res_tGyro.data(i,2)', ...
..
Index exceeds matrix dimensions.
Error in resample2 (line 44) fprintf(fid, '%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f', res_tAcc.data(i,1)', ...
You're running the loop over size(res_tAcc.data,1) but there's no guarantee that the others are necessarily identically the same size -- it appears at least one isn't as large.
Use size() on all the arrays you're wanting to output and ensure they're all at least as long as the one you've use.
BTW, for simplicity, a couple of things -- use repmat to make format strings manageable--
fmt=repmat('%f',1,15);
fprintf(fid,fmt,...
You can find the repeat count programmatically as well to save manual counting.
Also, build the array and output in one pass...
fmt=repmat('%f',1,16);
fprintf(fid,fmt,[res_tAcc.time(:,1) res_tAcc.data(:,1:3) res_tGyro.data(:,1:3) ...
res_tMagn.data(:,1:3) res_tOr.data(:,1:3) res_tRotQuatr.data(::3)].');
It would be even simpler and more regularly formatted if used dlmwrite or similar.
ERRATUM:
Also, build the array and output in one pass...
fmt=[repmat('%f',1,16) '\n'];
Forgot to add the newline...

その他の回答 (1 件)

José-Luis
José-Luis 2014 年 6 月 19 日
編集済み: José-Luis 2014 年 6 月 19 日
your_data = rand(60000,16);
fid = fopen('data.txt','w');
fprintf(fid, [repmat('%f ',1,size(your_data,2)) '\n'], your_data)
fclose(fid)
About 8MB. Please provide feedback on the answers you get.

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by