But when I enter [sound, freq] = wavread(file) into the command line, the variables store in the workspace.
storing data from function
16 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have this code in my function file: [sound, freq] = wavread(file) and for some reason sound and freq are not being stored in the workspace. What am I doing wrong?
採用された回答
Oleg Komarov
2012 年 5 月 31 日
If you're using wavread inside a function then you have to return them to your base workspace explicitly because the workspace of a function is kept separate.
Example, will not return sound and freq to the base workspace:
function foo(file)
[sound, freq] = wavread(file)
end
You have to declare the outputs explicitly:
function [sound, freq] = foo(file)
[sound, freq] = wavread(file)
end
and call it as
[out1,out2] = foo(file)
その他の回答 (1 件)
Stephen
2012 年 5 月 31 日
So, you have:
function something
[sound, freq] = wavread(file);
end
? If so, you need to output those values like
function [sound, freq] = something
then when you call the function, it will spit out those values. Otherwise, they only exist in the temporary workspace of the function, which gets cleared out when it's done
3 件のコメント
nazrin mokhtar
2020 年 2 月 28 日
i have same problem to save in workspace...can i know how to solve it
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!