I was designing a simple program(script file) for addition, a+b=c
3 views (last 30 days)
Show older comments
pawan singh
on 24 Jan 2020
Commented: Image Analyst
on 24 Jan 2020
I am new in MATLAB, I was designing a simple program(script file) for addition, a+b=c. where a is variable of 1x10, b is 1x10,and c is will also 1x10. but now if i need to change values of a and b from workspace, how to change it?. I am changing those values values of 'a' from workspace and runnning program, but these values are not changing. so my program is just fixed. i cant solve for any other value of 'a' and 'b'. please help me.
1 Comment
Mohammad Sami
on 24 Jan 2020
You should make a function.
function c = add(a,b)
c = a + b;
end
You can then call your function to add any values, as long as the their sizes are same.
Accepted Answer
Image Analyst
on 24 Jan 2020
If you want to do it from the workspace, set a break point just before you are going to use a and b. Then double-click on the variable name in the workspace panel to bring up the variable editor. Then type in the values you want, and click the continue >> button on the tool ribbon.
Most people would not do it that way - not sure why you want to.
2 Comments
Image Analyst
on 24 Jan 2020
What I would do is to make a GUI in GUIDE or App Designer, and place a spreadsheet (uitable) on it. Then have a button that says Add on it. The user then runs the program and can type anything into columns 1 and 2 and then push the Add button. Then in the Add button callback have this code
data = handles.uitable1.Data;
a = data(:, 1); % a is column 1.
b = data(:, 2); % b is column 2
c = add(a, b); % Call your function, or, more simply, just say c = a + b;
data(:, 3) = c; % Stuff c into column 3
handles.uitable1.Data = data; % Put data back onto GUI
More Answers (0)
See Also
Categories
Find more on Spreadsheets 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!