After last click everything in the workspace goes away
10 次查看(过去 30 天)
显示 更早的评论
Hello, I've got a strange problem. I created a function to read c3dfiles into Matlab. When I go through the code in debug mode, everything works fine. But when I click the last time to end the program, everything in the workspace disappears... So my code runs perfectly... Help please?
0 个评论
回答(2 个)
Star Strider
2014-12-28
I’m not certain what you’re doing, but I would like to know more about the context of: ‘But when I click the last time to end the program...’
Functions have their own workspaces, and when you exit a function, everything in its workspace disappears. Your function seems to read c3d files, but is apparently not passing those contents back to your calling program for it to use (and likely save to a .mat file to make reading and working with those data easier the next time).
You didn’t provide some important details (such as your code), so this is just a guess on my part.
1 个评论
Star Strider
2014-12-29
To keep ‘data_stari_rise’ in the workspace, change the first line of your function ‘read_data_stair_rise’ to:
function data_stair_rise = read_data_stair_rise
then in your main script, call it as:
data_stair_rise = read_data_stair_rise;
and ‘data_stair_rise’ will be in your workspace.
If you then use the save function to save it as ‘data_stair_rise.mat’, you can use the load function to get it back into your workspace whenever you want it, without having to read it again using your function. This isn’t necessary, but will make your programming easier, and likely more efficient.
Image Analyst
2014-12-28
That's normal. If you have a function in an m-file called unit_test.m, like this
function unit_test()
output = readcd3();
imshow(output);
end
function theImage = readcd3()
filename = 'c:\blah.png';
theImage = imread(filename);
end
Then if you step through in the debugger, at the imread() line inside readcd3() you'll see the workspace for readcd3 and ONLY for readcd3(). So only filename will appear in the workspace panel, until you execute the imread and then both filename and theImage will appear.
As you step out of the function and back into the main unit_test function, the workspace for readcd3 will vanish, and the workspace panel will now show the variables in the workspace for unit_test, and ONLY for unit_test.
Then as you step along and then stop at the imshow() line in the main program, output will still be there. It will be in the workspace for unit_test , which is the workspace you'll see when you're stopped at the imshow() line. However if you then click run or type F5, the function will exit, output will vanish along with the workspace for unit_test, and the workspace panel will now show the "base" workspace. All the function workspaces and variables have vanished at that point.
2 个评论
Image Analyst
2014-12-28
You don't need them to. Why would you? Any variables that you need later on, in a calling routine, you can just pass back as return arguments. Or write them out to a .mat file that some other code can read in later.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!