I'm simualting a project where one of the matlab functions states the following error:
"'y' is inferred as a variable-size matrix, but its size is specified as inherited or fixed. Verify 'y' is defined in terms of non-tunable parameters, or select the 'Variable Size' check box and specify the upper bounds in the Size box."
I have seen similar posts to this however couldn't find infomation on why my output is variable size,
The code for this aspect of the project is quite small and the following:
function y = sector(Valpha, Vbeta)
sector = [];
%all potential sectors for Vbeta greater than zero
if Vbeta>=0 & abs(Valpha) < abs(Vbeta/sqrt(3));
sector = 2;
end
if Vbeta>=0 & abs(Valpha) > abs(Vbeta/sqrt(3)) & Valpha >= 0;
sector = 1;
else sector = 3;
end
%all potential states for Vbeta less than or equal to zero
if Vbeta < 0 & abs(Valpha) < abs(Vbeta/sqrt(3));
sector = 5;
end
if Vbeta < 0 & abs(Valpha) > abs(Vbeta/sqrt(3)) & Valpha >= 0;
sector = 6;
else sector = 4;
end
y = sector;
Does anyone happen to know why the data is variable size and how I coulf stop it from being such.
Many thanks

댓글 수: 2

KSSV
KSSV 2021년 6월 24일
What are Valpha, Vbeta are they vectors?
Abd Al-Rahman Al-Remal
Abd Al-Rahman Al-Remal 2021년 6월 24일
They should be vectors yes

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

 채택된 답변

KSSV
KSSV 2021년 6월 24일

2 개 추천

Note that the function name and the variable are on the same name. This is not allowed.

댓글 수: 7

Abd Al-Rahman Al-Remal
Abd Al-Rahman Al-Remal 2021년 6월 24일
Oh sorry the 'sector' being the same right?
Abd Al-Rahman Al-Remal
Abd Al-Rahman Al-Remal 2021년 6월 24일
I'll try that now thank you!
Abd Al-Rahman Al-Remal
Abd Al-Rahman Al-Remal 2021년 6월 24일
Still getting the same error sadly
KSSV
KSSV 2021년 6월 24일
If the inputs are vectors, you cannot use the function like this.
Abd Al-Rahman Al-Remal
Abd Al-Rahman Al-Remal 2021년 6월 24일
Oh okay, do you know what kind of function I could use?
Obsviously you don't need to provide the code but the general name of the function if possible?
Thanks so much!
When you are comapring two vectors....you end up with a vector.
a = rand(10,1) ;
b = rand(10,1) ;
val = zeros(size(a)) ;
%
idx = a > b ;
val(idx) = 1 ;
You can proceed like shown above. So your sector values are going to be vectors.
Abd Al-Rahman Al-Remal
Abd Al-Rahman Al-Remal 2021년 6월 24일
Brilliant thank you so much for your help!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by