Making a Matrix calculator
    조회 수: 22 (최근 30일)
  
       이전 댓글 표시
    
I would like to make a calculator that would ask the user for the number of matrices involved, and then add, subtract, divide, or multiply said matrices. After some digging around, I think I could use while loops, and some switch/case loops to pull this off. I am wondering if this would be the best way to approach this, or if there were some other loops I might not have considered that could help me out. Any advice or suggestions would be appreciated.
답변 (2개)
  Prasanna
 2025년 4월 3일
        For Matrix Calculator, try this IF ELSE Case.
Take this example. It might be helpful for you.
a = input('Enter First Matrix: ');
b = input('Enter Second Matrix: ');
out = input('Operation to do: '); % ADD = 1/SUBTRACT = 2/MULTIPLY = 3/DIVIDE = 4
if out == 1 
    output_add = a+b
elseif out == 2
    output_subtract = a-b
elseif out == 3
    output_product = a*b
elseif out == 4
    output_divide = a/b
else
    fprintf('No proper input')
end
댓글 수: 0
  Umeshraja
 2025년 8월 18일
        
      편집: Umeshraja
 2025년 8월 18일
  
      If you’re just starting out with MATLAB and want a solid foundation, I recommend first completing the MATLAB Onramp course. It offers a great introduction to MATLAB basics and will help you feel more comfortable working with the environment.
To help build your matrix calculator, here are some useful resources to guide you:
- The official documentation on the 'input' function explains how to ask users for input and perform validation to ensure the data entered is correct.
- https://www.mathworks.com/help/matlab/ref/input.html?requestedDomain=
- For a clear overview of fundamental matrix operations such as addition, subtraction, and multiplication, refer to the MATLAB guide on matrix operations.
- https://www.mathworks.com/help/matlabmobile/ug/matrix-operations.html
- To understand the differences between element-wise operations and matrix operations (for example, the distinction between * and .*), check the page comparing array and matrix arithmetic.
- https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
- Lastly, there is a resource detailing all matrix arithmetic operators and how to use them properly.
- https://www.mathworks.com/help/simulink/matrix-operations.html
- Additionally, if you want to learn about element-wise multiplication
- https://www.mathworks.com/help/matlab/ref/double.times.html
Hope this helps!
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




