finding min max in matrix with loops and condintion only

2 次查看(过去 30 天)
hi, its me again, got an exam next week. I need to find the ma number and min number and then print them,this what I comefore please help me with sintaxx and right writing
n=randi(6);
a=randi(100,n,n);
b=a(1,1);
for i=1:n
{
for j=1:n
{
if a(i,j)<=a(1,1);
b=a(i,j);
end
}
};
fprintf('min num is x=%d/n',b);

回答(1 个)

Jan
Jan 2017-9-17
You have an exam next week and still do not know how to write a for loop in Matlab and how to use the documentation to find out how to do this?
doc for
Matlab does not use curly braces for code branches. This was C. Simply omit them.
The rest of the code is almost working. You do not want to compare the elements with a(1,1), but with b in
if a(i,j) <= a(1,1)
  7 个评论
Walter Roberson
Walter Roberson 2017-9-19
"How often did you get the $5 offer?"
For me, twice in 7 years. One of those two was after I had already done the work, and the person didn't even send the money... The other was $5 to do a homework assignment.
In my experience, as soon as I mention money, the person decides their task is not so urgent after all. I don't recall that I have ever gotten as far as mentioning how much I charge: people lose interest upon finding out that I do charge for writing custom programs or for private consultation.
Jan
Jan 2017-9-19
编辑:Jan 2017-9-19
The offer of payments in the funny magnitude of some US$ came about twice per month. Assisting naive students with cheating might be more lucrative if you are willing to blackmail and ask for more money after the exams.
This forum offers assistance for free and I'm sure you can get all homework question solved here, if the own effort is shown and specific questions are asked.
Some years ago a person offered 5$ per minute, seriously, for a work over some month. He was a hedge fond manager, expected a 25/8 support and needed a software to destroy companies such, that the most money can be squeezed out. Frightening. I thought about how I would look, if he buys the company I'm employed in and crush it. Career switches are overestimated.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Historical Contests 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by