size mismatch using find command
1 view (last 30 days)
Show older comments
Jirada Gosumbonggot
on 5 Dec 2017
Commented: Jirada Gosumbonggot
on 5 Dec 2017
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
0 Comments
Accepted Answer
Walter Roberson
on 5 Dec 2017
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()
More Answers (0)
See Also
Categories
Find more on Sources 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!