How can I create a matrix of equal element value?
Show older comments
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
More Answers (1)
Matt J
on 13 Mar 2015
clear y;
y(1:5,1:80)=5;
9 Comments
Nnedoe
on 13 Mar 2015
James Tursa
on 13 Mar 2015
What is the pattern of 1's and 0's?
Nnedoe
on 13 Mar 2015
James Tursa
on 13 Mar 2015
Yes, but the code for that is going to depend on the pattern of 1's and 0's. What is this pattern?
Nnedoe
on 13 Mar 2015
Edited: James Tursa
on 13 Mar 2015
It can be done in one line as
m=(P1>=75);
Example:
>> P1=[80,60,77,59]; m=(P1>75)
m =
1 0 1 0
Nnedoe
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);
Nnedoe
on 13 Mar 2015
Categories
Find more on Creating and Concatenating Matrices 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!