storing data set

my code returns a 200X200 matrix which has a structure in each of its element. Can I save/store it somewhere and load it later. The system seems to lose it when i close matlab. if i save the variable as .mat file in my workspace it cannnot bring it up later.

回答 (2 件)

carmen
carmen 2012 年 2 月 16 日

1 投票

sure :)
ok my answer was kind of an overkill, sorry! let "a" be your 200x200 variable and "savea.mat" the file you want to save to. then the command that should do the job is
save('savea','a')
load('savea','a')
what i used above is the sprintf function that allowed me to save to dynamic file and foldernames. in this case sprintf had 3 arguments, "'%s\\%s\\filename'" ,"pwd" and "'foldername'". the first is a string that is interpreted where the %s places the content of the second an third argument in that position. pwd is a matlab command that returns the current matlab folder, let it be "C:\matlab". then:
foldername='fancyfolder'
save(sprintf('%s\\%s\\savea',pwd,'foldername'),'a');
should save the variable a into the file C:\matlab\fancyfolder\savea.mat note that you need the backslash and the "%" sign have special meaning within the sprintf function.
does this help?

6 件のコメント

Pankaj
Pankaj 2012 年 2 月 16 日
thanks Carmen.
Thanks for explaining me the construct. the save('name','var') seems to work. but it is taking a long time to save. Its been 10 mins i punched it in and its still showing busy. :)
i'll let you know how it goes. thanks again
Oleg Komarov
Oleg Komarov 2012 年 2 月 16 日
200 by 200 is a heavy structure. Could you post it's size in bytes?
Pankaj
Pankaj 2012 年 2 月 19 日
The size in Bytes is close to 5.75GB
KUMAR ADITYA
KUMAR ADITYA 2017 年 5 月 9 日
That is one big matrix bro
KUMAR ADITYA
KUMAR ADITYA 2017 年 5 月 9 日
Thanks carmen.....helped me a lot even after 5 years......!!!
Panagiotis Papias
Panagiotis Papias 2022 年 2 月 11 日
Guess what is the year 2022 and still somebody can find it really useful :)

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

carmen
carmen 2012 年 2 月 15 日

0 投票

I onec used
save(sprintf('%s\\%s\\filename',pwd,'foldername'),'varname');
load(sprintf('%s\\%s\\filename',pwd,'foldername'),'varname');
where pwd returns the current matlab workspace folder. if this does not help you i dont know :(

1 件のコメント

Pankaj
Pankaj 2012 年 2 月 15 日
Hi Carmen, thanks for your help - but i am not able to understand the command - can you please spare a min to explain : %%s, \\filename, 'foldername', 'varname'.
tried doc but didn't help

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

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

製品

タグ

質問済み:

2012 年 2 月 15 日

コメント済み:

2022 年 2 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by