3 × 3 hit

1 次查看(过去 30 天)
Rusel Ibrahim
Rusel Ibrahim 2021-6-6
Q1) write matlab mfile program to input 3x3 A matrix and then call a function that multiply each elements of odd columns from this matrix by 4 then display the result after execute the function?
  1 个评论
Steven Lord
Steven Lord 2021-6-6
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

请先登录,再进行评论。

回答(1 个)

Manas Minnoor
Manas Minnoor 2021-6-6
Hi Rusel,
Assuming you want to input the numbers one by one, you may use nested for loops along with the input function, whose documentation are linked below.
To multiply odd columns by 4, you may again use nested for loops along with the colon operator to access only odd columns.
Hope this helps.
  1 个评论
DGM
DGM 2021-6-6
select odd columns of A:
A(:,1:2:end);
select even columns of A:
A(:,2:2:end);
no loops needed.
Requiring users to manually input everything anew every time a script is run is just plain bad in my opinion. It's a waste of the user's time and concentration and only promotes errors, but I guess the people writing homework assignments love it. I don't doubt that's the intended way.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by