How can I create a matrix of equal element value?

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]

More Answers (1)

clear y;
y(1:5,1:80)=5;

9 Comments

Thanks Matt, it worked and it is sophisticated. If I can do this for elements of the same value, is this possible for binary? a matrix of ones and zeros only
What is the pattern of 1's and 0's?
yes. What I mean is,can I write a 5 by 80 matrix of ones and zeros without necessarily writing a condition statement?
Yes, but the code for that is going to depend on the pattern of 1's and 0's. What is this pattern?
Okay, lets look at this example: I have 2 machines that run for 30 production intervals, at some point I will like to turn a machine off (m = 0),for maintenance when its production rate is less than 75 parts per hour(P < 75), otherwise m = 1. If the machine of focus here is machine 1, the code may begin as:
k = 1:30;
clear P_threshold;
P_threshold(1:2,1:30)=75;
P1(k) = ones(2,30);
if ( P1(k) < P_threshold)
m = 0;
else
m = 1;
end
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
Matt, the problem I have now is that the value of p1 at different intervals [p1(k)] is yet to be determined and I need a binary matrix that can change as the values are calculated. My original problem is a MINLP problem and I will like to create a binary matrix that takes has element values of ones and zeros as p1(k) is determined. How can I do this?
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.

Categories

Asked:

on 13 Mar 2015

Commented:

on 13 Mar 2015

Community Treasure Hunt

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

Start Hunting!