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

조회 수: 68 (최근 30일)
I am trying to find solution for the below code.. The excel file has 7935 data of d variable in a single column.
I have to find the position of HL and store the index value. It shos the error message of "Unable to perform assignment because the left and right sides have a different number of elements." after assigning 10th variable in the loop.
T = xlsread('CPT_13_14_15_18_22.xlsx','U-13');
d = T(:,1);
uw = T(:,2);
HL = [0.5 26.2 29.5 32.9 38.2 40.7 47.15 48.75 49.75 58.65 59.9 61.1 69.5 71.6 88 90.1 121.15];
for i = 1:length(HL)
a(i) = find(d==HL(i));
end

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 2월 23일
편집: Cris LaPierre 2024년 2월 26일
This error occurs because you are trying to assign more than 1 value to one element of a.
% this Works
a(1) = 5;
% This duplicates the error
a(2) = [2 3]
Unable to perform assignment because the left and right sides have a different number of elements.
You either need to ensure you only assign a single value, or adjust the assignment so that the number of elements indexed are the same on the left and right of the equals sign.
% Use a cell array
b(1) = {[2,3]}
b = 1×1 cell array
{[2 3]}
% Or specify the columns, too
c(1,:) = [2,3]
c = 1×2
2 3

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by