# Subscripted assignment dimension mismatch.

4 visualizzazioni (ultimi 30 giorni)
image-pro il 13 Apr 2022
Commentato: Rik il 14 Apr 2022
i am new in matlab please solve this error
I=rgb2gray(M);
[X, Y, depth]=size(I);
[X,Y]=meshgrid(1:X,1:Y);
output = [I(:), X(:), Y(:)];
n = 50;
x = X;
fx = Y;
% The values f(x_i) are stored in the first column of
% an (n+1)*(n+1) matrix F.
F = zeros(n+1, n+1);
F(:, 1) = fx;
% Compute the Newton divided differences.
for i=1:n
for j=1:i
F(i+1,j+1) = (F(i+1,j)-F(i,j)) / (x(i+1)-x(i-j+1));
end
end
% Print out the coefficients of the interpolation,
% which is given by F(1,1), F(2,2), F(3,3), ... F(n+1,n+1).
% Then the Lagrange interpolation is
% (here all indices have been shifted so it starts from 1 and end at n+1)
% F(1,1) + F(2,2)*(x-x1) + F(3,3)*(x-x1)*(x-x2) + ...
% + F(n+1,n+1)*(x-x1)*(x-x2) ... (x-xn)
% We can use the Matlab command "diag" to get these diagonal elements.
a = diag(F);
% Next, we would like to draw the graph of the Lagrange interpolation.
% To do this, we first need to evaluate the polynomial at a set of points.
% The x and y coordinates of these points are stored in plotx and ploty.
plotx = -2:0.1:3;
% Evaluate the value of the Lagrange interpolation "Horner-style".
ploty = a(n+1)*ones(size(plotx));
for i=n:(-1):1
ploty = a(i) + ploty.*(plotx-x(i));
end
% Draw the graph.
% The curve is the interpolation,
% and the given points (x_i, f(x_i)) are shown as stars.
figure(1);
plot(plotx, ploty, '-', x, fx, '*');
I am getting following error
Subscripted assignment dimension mismatch.
Error in p7 (line 14)
F(:, 1) = fx;
##### 11 CommentiMostra 9 commenti meno recentiNascondi 9 commenti meno recenti
image-pro il 14 Apr 2022
The goal of my code is to find the effected pixel value
Rik il 14 Apr 2022
No, it is not. What I mean is something else: why did you write imwread? If you need to find a value, you can use find. The answer is that you don't intend to 'find a value', you want to prepare variables for your loop.
I don't understand your equations well enough to be able to guess how you need to pre-process your image to make it ready for the loop. That is what I'm trying to find out.
The goal of the loop is to calculate the pixel value, the goal of the code prior to the loop is to pre-process your data. Your code is devoid of any comments explaining why you need any of the variables you're creating. That is why we're already 10 comments deep into this conversation without the actual problem being clear yet.

Accedi per commentare.

### Categorie

Scopri di più su Interpolation in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by