size mismatch using find command

조회 수: 4 (최근 30일)
Jirada Gosumbonggot
Jirada Gosumbonggot 2017년 12월 5일
댓글: Jirada Gosumbonggot 2017년 12월 5일
Hi,
I write the code using find command to find the index of match data in array. But I received an error about mismatch
for j = 1:n
[~,d] = min(abs(V1-Vscan_start(j,1)));
Vscan_start_round(j,1) = V1(d);
Vscan_start_loc(j,1) = find(V1 == Vscan_start_round(j,1));
Isc(j,1) = I1(Vscan_start_loc(j,1));
[~,e] = min(abs(V1 - Vscan_end(j,1)));
Vscan_end_round(j,1) = V1(e);
Vscan_end_loc(j,1) = find(V1) == Vscan_end_round(j,1));
end
The inputs are V1 and I1 which are arrays. The error is on "find" command. When I typed this in command window it works. However, when run in simulink it shows error.
Size mismatch ([1 x 1] ~= [:? x 1]).
Function 'Short term sampling tracking/shorttrack' (#23.1252.1311), line 40, column 5:
"Vscan_start_loc(j,1) = find((V1) == Vscan_start_round(j,1))"
Launch diagnostic report.
Any suggestion for me? thank you so so much in advance

채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 5일
Simulink has no reason to expect that each find() will return exactly one index: as far as it knows, the search could return 0, 1, or several values. That is not acceptable for MATLAB Function Blocks if any acceleration is turned on at all.
When I look at your code, and read your description, I see no reason why
Vscan_start_round(j,1) = V1(d);
should work. You constructed d as min() of an array expression, so d will be a vector, each entry of which is a row index (not array index). You then use those row indices as linear indices into the array, which is bad logic, but in any case will return a vector of values. You then try to store that vector of values into a single location.
If your description was wrong and V1 is a vector then the code would make more sense -- but there would be no point to the code if you can guarantee that exactly one result will be found: since the value to be matched against has been extracted from the vector being searched, if you could guarantee that exactly one value would be found then it would have to be at the location that the data was extracted from, in which case you might as well just use that location directly instead of doing a find()
  댓글 수: 1
Jirada Gosumbonggot
Jirada Gosumbonggot 2017년 12월 5일
Dear Walter
Thanks for your comment. I have simplified the code by putting the index directly without using find command and it works.
for j = 1:n
[~,d] = min(abs(V1-Vscan_start(j,1)));
Vscan_start_round(j,1) = V1(d);
Isc(j,1) = I1(d);
[~,e] = min(abs(V1 - Vscan_end(j,1)));
Vscan_end_round(j,1) = V1(e);
end
Thanks again

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by