I was designing a simple program(script file) for addition, a+b=c
조회 수: 3 (최근 30일)
이전 댓글 표시
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
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
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
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 Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!