How to save workspace variables in a cell array at specific location (Example: C{1,1}(1,1)) in the same workspace?
Show older comments
I want to save a workspace variable at location C{1,1}(1,1) in a cell array which is present in the same workspace. I used this command. It executes in command window but the same logic fails in editor window when written at button callback.
M = 1:10;
M = M';
C = {M};
assignin('base','C',C);
C{1,1}(1,1) = 55;
3 Comments
Note that assignin is the least recommended way of passing data between callbacks:
Using assignin makes your work harder to debug, as you are now finding out. Much better would be to use the handles structure, guidata, or nested functions.
N/A
on 4 May 2017
Stephen23
on 4 May 2017
@Tanzeela Javid: and what happens when you try to execute that line? Do you get a warning, or an error, or the wrong value, or something else...? If you get any warning/error message then please show us the complete message. If it runs but gives an incorrect value (or something else...) then please tell us what you expect and what it does.
Answers (2)
N/A
on 5 May 2017
0 votes
4 Comments
Please do not post details of the question in the section for answer. I have problem zoominh into the screen shot. Prefer to post error messages as text and format your code using the "{} Code" button. This helps the readers to understand your problem.
Please read the documentation of assignin: doc assignin. The 2nd input must be a string, namely the variable to be assigned.
Do not try to change elements of a cell remotely. Such indirect programming methods impedes the debugging. Better create the variables inside the GUI, see the links posted by Stephen.
N/A
on 5 May 2017
N/A
on 5 May 2017
Stephen23
on 5 May 2017
@Tanzeela Javid: I gave you some links to look at. Personally I think using nested functions is a very easy way to share data between callbacks. Give them a try.
N/A
on 5 May 2017
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!