%$Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1.
%$Error in machine_problem (line 39)
%$ p_new(j,1) = w*a + z*b; "
%code
states = [0; 3; 3; 5; 6; 8; 8; 11];
fors = [0.02;0.02;0.02];
capacities =[3;3;5];
p_old = 0;
for i=1:length(capacities)
fprintf('Adding unit: %d \n',i);
p_new = 0;
for j = 1:(2^i)
if states(j,1) == 0
[a]= 1;
elseif j >= (2^i)
[a] =0;
end
if (states(j,1) - capacities(i,1)) <= 0
[b] = 1 ;
else
x = find(states == (states(j,1)-capacities(i,1)));
[b] = p_old(x,1);
end
[w] = 1 - fors(i,1)
[z] = fors(i,1)
p_new(j,1) = w*a + z*b;
end
p_old = p_new;
disp(p_new);
end

 채택된 답변

Walter Roberson
Walter Roberson 2022년 5월 21일

0 개 추천

if states(j,1) == 0
[a]= 1;
elseif j >= (2^i)
[a] =0;
end
what if neither of those is true? What will a be initialized to?
x = find(states == (states(j,1)-capacities(i,1)));
How do you know that exactly one such location exists?

댓글 수: 2

Winston Sabellona
Winston Sabellona 2022년 5월 21일
Thank you Mr. Roberson. Honestly, im stuck with this. Do you have any recommendations pls?
%code
states = [0; 3; 3; 5; 6; 8; 8; 11];
fors = [0.02;0.02;0.02];
capacities =[3;3;5];
p_old = 0;
for i=1:length(capacities)
fprintf('Adding unit: %d \n',i);
p_new = 0;
for j = 1:(2^i)
if states(j,1) == 0
[a]= 1;
elseif j >= (2^i)
[a] =0;
else
error('a undefined');
end
if (states(j,1) - capacities(i,1)) <= 0
[b] = 1 ;
else
x = find(states == (states(j,1)-capacities(i,1)));
[b] = p_old(x,1);
end
[w] = 1 - fors(i,1)
[z] = fors(i,1)
temp = w*a + z*b;
p_new(j,1:numel(temp)) = temp;
end
p_old = p_new;
display(p_new);
end
Adding unit: 1
w = 0.9800
z = 0.0200
w = 0.9800
z = 0.0200
p_new = 2×1
1.0000 0.0200
Adding unit: 2
w = 0.9800
z = 0.0200
a undefined

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Phased Array System Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by