How do I use function for a function which has a matrix with variable index?

1 ビュー (過去 30 日間)
Fidele Adanvo
Fidele Adanvo 2020 年 11 月 17 日
コメント済み: Fidele Adanvo 2020 年 11 月 17 日
if AR<Max
%PacksB, PacksA, ContB, ContA are a vector that varies according to the operation
PacksB=3; fB=fB+1;
PacksA=2; ContA(AR+1)=i; AR=AR+1;
if BR==1
PacksB(ContB(1))=4; fB=fB+1;
ContB(1)=0; BR=BR-1;
elseif BR>=2
PacksB(ContB(1,1:2))=4; fB=fB+2;
if BR==2
ContB(1)=ContB(3); ContB(1,2:3)=0;
elseif AR==Max
PacksA=3; fA=fA+1;
PacksB=3; fB=fB+1;
if BR>0
PacksB(ContB)=4; fB=fB+BR;
%Hello, can you help me solve this error?
%Error in ==> OutAR_NotOutBR at 2
if AR<Max
{??? Output argument "PacksA" (and maybe others)
not assigned during call to

回答 (1 件)

James Tursa
James Tursa 2020 年 11 月 17 日
編集済み: James Tursa 2020 年 11 月 17 日
You don't have a branch for the AR>Max case. If you hit that condition, the output variables will not be assigned. Also, ContA doesn't appear to be set in the AR==Max case.
You should check that in all of the possible paths through your code, all of the output variables get assigned to something.
  8 件のコメント
Fidele Adanvo
Fidele Adanvo 2020 年 11 月 17 日
Por exemple: if i=5
function []=()
PackA(5)=7 it's an example.
As you can see, I don't need to go through all the PacksA elements.



Find more on Resizing and Reshaping 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!

Translated by