I was designing a simple program(script file) for addition, a+b=c

3 ビュー (過去 30 日間)
pawan singh
pawan singh 2020 年 1 月 24 日
コメント済み: Image Analyst 2020 年 1 月 24 日
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 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 1 月 24 日
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.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 1 月 24 日
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 件のコメント
pawan singh
pawan singh 2020 年 1 月 24 日
編集済み: Image Analyst 2020 年 1 月 24 日
Sir, actually I would like to make program to add two coloumns and get third coloums. same as like in excel.
in excel, if we are changing values of our two input coloums its automatically changes values in third obtained coloumn. in similar fashion, i want to make a program.
but here in MATLAB, I am not able to change any input variable values.
function c = add(a,b)
c = a + b;
end
after running this code
function c = add(a,b)
|
Error: Function definitions are not permitted in this context
this error is coming out.
Image Analyst
Image Analyst 2020 年 1 月 24 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by