필터 지우기
필터 지우기

Matlab app designer confuses the end written inside matrix index with the end for if and for loop

조회 수: 2 (최근 30일)
Hi all
I got a piece of my code that is causing function nesting error and the root cause is that matlab is not understanding the end written in Matrix(end)
is not related to the loop or function end and has messed up
exactly where I haveTtot(end) , this end is confused
for fn=1:numel(files)
ff= xlsread(strcat(files{fn},'.xlsx'));
filename=files{fn};
t = ff(:,1);
resol=t(2)-t(1);
motion6t=ff;
mulnames=readcell('Ms.xlsx')
mask = strcmp(filename, mulnames(:,1));
multip = cell2mat(mulnames(mask, 2));
resol=t(2)-t(1)
if fn==1
motiontot=[];
for m=1:multip
if m==1
Ttot=t.';
else
Ttot= [Ttot,t.'+Ttot(end)+resol];
end
end
else
for m=1:multip
Ttot= [Ttot,t.'+Ttot(end)+resol];
end
end
for m=1:multip
motiontot=[motiontot;motion6t];
end
end
  댓글 수: 11
farzad
farzad 2020년 5월 13일
Dear Walter, I checked, and it seems that whenever I remove this block , the whole code is ok. the only suspicious ' sign, was t.' in the summation equation with Ttot. but when I removed it, I still have the same error. I had some variables with the warning : the variable spans among more functions. I resolved it as well, but still I have the same problem :
for fn=1:numel(files)
ff= xlsread(strcat(files{fn},'.xlsx'));
fname=files{fn};
t = ff(:,1);
resol=t(2)-t(1);
motion6t=ff;
cd(myperc)
mulnames=readcell('Multipliers.xlsx');
mask = strcmp(fname, mulnames(:,1));
mu = cell2mat(mulnames(mask, 2));
resol=t(2)-t(1);
if fn==1
motiontot=[];
for m=1:mu
if m==1
mTtot=t;
else
mTtot= [mTtot ,t.'+mTtot(end)+resol];
end
end
else
for m=1:mu
mTtot= [mTtot ,t.'+mTtot(end)+resol];
end
end
for m=1:mu
motiontot=[motiontot;motion6t];
end
farzad
farzad 2020년 5월 13일
편집: farzad 2020년 5월 13일
Ok this is the complete code, and trying this on workspace I get error on mTtot:
Array indices must be positive integers or logical values.
Error in test (line 47)
mTtot= [mTtot ,t.'+mTtot(end)+resol];
mydir=uigetdir()
content = dir('*.xlsx');
content([content.isdir]) = []; % remove directories
files = cell(size(content));
% Extract the filename without the extentions
for fi = 1:numel(files)
[~, files{fi}] = fileparts(content(fi).name);
end
for fn=1:numel(files)
ff= xlsread(strcat(files{fn},'.xlsx'));
fname=files{fn};
t = ff(:,1);
resol=t(2)-t(1);
motion6t=ff;
mulnames=readcell('Ms.xlsx');
mask = strcmp(fname, ulnames(:,1));
mu = cell2mat(mulnames(mask, 2));
mTtot=[];
resol=t(2)-t(1);
if fn==1
motiontot=[];
for m=1:mu
if m==1
mTtot=t;
else
mTtot= [mTtot ,t.'+mTtot(end)+resol];
end
end
else
for m=1:mu
mTtot= [mTtot ,t.'+mTtot(end)+resol];
end
end
for m=1:mu
motiontot=[motiontot;motion6t];
end
maxlim=max(max(motion6t(:,2:7)));
minlim=min(min(motion6t(:,2:7)));
directory=pwd;
end

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 13일
mTtot=[]
size(mTtot)
mTtot =
[]
ans =
0 0
with it being empty, end as an index would be 0. mTtot(end) would be mTtot(0) which is not permitted.
mTtot= [mTtot ,t.'+mTtot(end)+resol];
Perhaps you are wanting mTtot(end) to be empty instead of an error when mTtot is empty. But if that were the case, then you would have the situation
mTtot = [[], t.'+[]+resol]
and anything + [] is [], so you would be dealing with
mTtot = [[], []]
which would leave mTtot empy, but I suspect you are trying to append to it in that statement,.
  댓글 수: 16

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by