I was designing a simple program(script file) for addition, a+b=c
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
pawan singh
le 24 Jan 2020
Commenté : Image Analyst
le 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 commentaire
Mohammad Sami
le 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.
Réponse acceptée
Image Analyst
le 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 commentaires
Image Analyst
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!