Clear Filters
Clear Filters

finding min max in matrix with loops and condintion only

1 view (last 30 days)
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);

Answers (1)

Jan
Jan on 17 Sep 2017
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 Comments
Walter Roberson
Walter Roberson on 19 Sep 2017
"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 on 19 Sep 2017
Edited: Jan on 19 Sep 2017
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.

Sign in to comment.

Categories

Find more on Historical Contests in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!