problem with storing in an array
Show older comments
% The previous code was omitted
% Part of the code for the preliminary detection of extreme points
num = 0;
extreme_point = [];
for oct_i = 1 : octave
dog = dog_pyr{oct_i};
[dog_r, dog_c, dog_page] = size(dog);
for r = 6 : dog_r - 5
for c = 6 : dog_c - 5
for page_i = 2 : dog_page - 1
dog_near = zeros(3, 3, 3);
dog_near(:, :, 1) = dog(r - 1 : r + 1, c - 1 : c + 1, page_i - 1);
dog_near(:, :, 2) = dog(r - 1 : r + 1, c - 1 : c + 1, page_i);
dog_near(:, :, 3) = dog(r - 1 : r + 1, c - 1 : c + 1, page_i + 1);
point_vale = dog_near(2, 2, 2);
if (point_vale == max(dog_near(:))) || (point_vale == min(dog_near(:)))
num = num +1;
sigma_i = k ^ (page_i -1) * sigma0;
extreme_point(num, :) = [oct_i, page_i, r, c, sigma_i, 0]; % ???
end
end
end
end
end
hi, I'd like to ask you a questio, about the last line "extreme_point(num, :) = [oct_i, page_i, r, c, sigma_i, 0];", Pls if it is written "extreme_point(num) = [oct_i, page_i, r, c, sigma_i, 0];", an error message that the assignment cannot be performed because the index on the left is incompatible with the size on the right will appear.
May I ask why this error occurs?
At the beginning of learning not quite understand, this is about the sift algorithm part of the content, the overall problem is all machine rollover, please understand.
Accepted Answer
More Answers (2)
dpb
on 16 Jul 2024
In
extreme_point(num, :) = [oct_i, page_i, r, c, sigma_i, 0];
the RH side is a vector of 6 elements; as written, the LH side puts that into a row of a (growing) 2D array.
If the LH side subscripting expression is written as only (num), you would be trying to put six things into a single location -- that doesn't work. The only way to have a single subscript would be if you were to put the vectors each into a single cell in a cell array --
extreme_point{num} = [oct_i, page_i, r, c, sigma_i, 0];
would work, but note the difference between the two expressions. The "curlies" {} around the subscript create a cell array, which can hold an array.
Jatin
on 16 Jul 2024
0 votes
Hi,
This error usually occurs due to a mismatch in the dimensions of array you are trying to assign values to.
In this case the left-hand side i.e., “extreme_point(num)” is trying to assign an element to extreme_point at numth index, whereas the right-hand side i.e., “[oct_i, page_i, r, c, sigma_i, 0]” is not an element but a row vector. Hence, we are getting an error stating “the assignment cannot be performed because the index on the left is incompatible with the size on the right.”
The right way to assign is to use “extreme_point(num,:)” which says assign a row vector at the numth row of “extreme_point”.
Kindly refer this documentation for more understanding of multidimensional array in MATLAB
Categories
Find more on Time Series Objects 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!