How can I create a program that allows the user to enter a matrix of any size and replaces only the negative values in the matrix with -100?

Im a beginner at matlab and I can't solve this simple problem. I know a forloop is involved but I am still unsure how to do this.

Answers (1)

x( x < 0 ) = -100;
will replace negative values of x with -100. Allowing a user to create a matrix depends how you want to do it. Either a GUI or just on command line.
For loops shouldn't be anywhere near this problem though!

This question is closed.

Asked:

on 27 Mar 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!