How can I create a matrix of equal element value?

34 views (last 30 days)
If I want to create a 5 by 80 matrix of value 121 for each element, how can I do that? example A variable y is a 2 by 2 matrix of value 5 for each element is : y = [5,5;5,5]

Accepted Answer

James Tursa
James Tursa on 13 Mar 2015
y = 121*ones(5,80);

More Answers (1)

Matt J
Matt J on 13 Mar 2015
clear y;
y(1:5,1:80)=5;
  9 Comments
Matt J
Matt J on 13 Mar 2015
Edited: Matt J on 13 Mar 2015
Well, you would use a for-loop, I'd imagine. But you can create the P1 matrix first using a loop or whatever vectorizable means are available, then still create 'm' in one line as
m=(P1>=75);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!