필터 지우기
필터 지우기

Unable to perform assignment because the left and right sides have a different number of elements.

조회 수: 2 (최근 30일)
Hi, I'm trying to do a for loop as following.
It can loop up to 633 times but can't do more and I got the error message as in the title.
I appreciate if you could teach me how to solve this.
load variables
for j = 1:length(r)
[content(j)] = vlookup(AC, r(j), 2, 1);
end

채택된 답변

Turlough Hughes
Turlough Hughes 2021년 8월 20일
편집: Turlough Hughes 2021년 8월 20일
Your vlookup is not returning a value when j = 634. You will need a condition to deal with this when it happens.
For example:
load variables
k = 1; % loop variable
content = zeros(size(r)); % preallocate
for j = 1:length(r)
v = vlookup(AC, r(j), 2, 1);
if ~isempty(v)
content(k) = v;
k = k+1; % increment k
end
end
% remove excess rows that arose due to empty output from vlookup
idel = find(content~=0,1,'last');
content(idel+1:end) = [];
  댓글 수: 3
Turlough Hughes
Turlough Hughes 2021년 8월 21일
Happy to help and welcome to MATLAB Answers! Please accept the best answer when you're happy the question has been fully addressed.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by