Generates 1xN vector (row), symbol values A0 and A1

조회 수: 1 (최근 30일)
Sotiris Katsimentes
Sotiris Katsimentes 2022년 4월 8일
댓글: Sotiris Katsimentes 2022년 4월 11일
Hello,
I have a problem. I have an project and i want to:
Generates 1xN vector (row), symbol values A0 and A1, where A0=-A1 and A0=2, p0 is the probabilty to have A0 and is p0=0.5
I have also to replicate first row with N values M times.Each column in the MxN matrix has identical value. I am facing a real problem and i don't know how to do it exactly and correclty.
thank you very much in advance.
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2022년 4월 10일
Follow up questions and comments -
  • Are A0 and A1, singular values or arrays?
  • "However, I want this vector to be created with some possibility. That is, p0 will be the probability that I have the value A0 and I want p0 = 0.5." > I am still not sure what these means.
  • You need to define only 1st row, rest you can replicate by using
repelem(y,1,M-1) %y is your initial row (1xN)
Sotiris Katsimentes
Sotiris Katsimentes 2022년 4월 10일
  • Yes A0 and A1 are singular values, for example A0=1 and A1=-1
  • In order to make it more understandable for example I want to create such a table. In each line of the vector I want to have an alternation of values A0 and A1, which in this example these values are -1 and 1. I want the probability p0 = 0.5 which means that in each row of the vector to have equal numbers A0 and A1, ie the probability of occurrence ρ0 = 1/2 and respectively ρ1 = 1/2
  • thank you very much for your help and idea

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2022년 4월 10일
편집: Dyuman Joshi 2022년 4월 10일
A0=1; A1=-A0;
%N=input ('Enter a number \ n');
%check if N is an even number by using ifelse
N=8; %using a random value for example
M=7;
%this is for probablity 0.5
%I think you want all rows to be different so we won't use repmat/repelem
for i=1:M
z=randperm(N);
y(i,:)=A0*(rem(z,2)-(~rem(z,2))); %takes in consideration different values of A0
end
y
y = 7×8
-1 1 1 1 -1 -1 -1 1 1 1 1 -1 -1 1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 -1 -1 1 1 -1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2022년 4월 11일
You are welcome!
Since the probability is 50-50 it was easier to do. What I did is generate random permutation of 1 to N. There's a 50-50 chance that a random number from 1 to N will be even or odd. I utilized that. Hope this helps.
Sotiris Katsimentes
Sotiris Katsimentes 2022년 4월 11일
I have one more question. If i want to generate a vector row with A0 and A1 with this probability p0(for N values),and then replicate it in matrix for M samples, how i can do that ??
as you metioned before "replicate" will be done by "repelem(y,1,M-1) %y is your initial row (1xN)"
So i want to tell me if you know how i can generate the vector row with this feature

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by