Hi, i am here to complete my project on a MATLAB GUI, but I have some syntax errors. Help me out.

5 ビュー (過去 30 日間)
u=multibandread('paris.lan',[512,512,7],'uint8=>uint8',128,'bil','ieee-le');
[x,y]=ginput(1);
[xx,yy]=ginput(1);
[xxx,yyy]=ginput(1);
[xxxx,yyyy]=ginput(1);
Nof_bands=7;
for k=1:Nof_bands
t_value=u(:,:,k);
X(k)=double(t_value(x,y));
Y(k)=double(t_value(xx,yy));
Z(k)=double(t_value(x,y));
b(k)=double(t_value(xx,yy));
x1(k)=double(t_value(xxx,yyy));
y1(k)=double(t_value(xxxx,yyyy));
z1(k)=double(t_value(xxx,yyy));
b1(k)=double(t_value(xxxx,yyyy));
avg(k)=double(X(k)+Y(k)+Z(k)+b(k))/4;
avg1(k)=double(x1(k)+y1(k)+z1(k)+b1(k))/4;
end
z=xcorr2(double(avg),double(avg1));
axes(handles.axes2);
plot(z);
title('correlation of 2 signals');
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 6 日
ginput returns X coordinates in the first variable and Y coordinates in the second variable. You use a for the X coordinates and b for the Y coordinates. You index t_value(a,b), which is what you would do if the first index into an array was X and the second was Y. However, in MATLAB, the first index into an array is Y and the second is X, so you would need t_value(b,a)
(Also, I recommend rounding the coordinates.)
In MATLAB, the first index is rows and the second is columns, which corresponds to the standard reading for tables of data, such as "Line 5, column 3" meaning that you go down the rows to row 5, and across from there to column 3. This is a very common convention. This convention happens to be at odds with typical cartesian coordinate placement of x first and then y.
deepika
deepika 2018 年 7 月 6 日
編集済み: Image Analyst 2018 年 7 月 7 日
[a,b]=ginput(1);
[xx,yy]=ginput(1);
[xxx,yyy]=ginput(1);
[xxxx,yyyy]=ginput(1);
Nof_bands=7;
for k=1:Nof_bands
t_value=im(:,:,k);
X(k)=double(t_value(b,a));
Y(k)=double(t_value(yy,a));
Z(k)=double(t_value(b,xx));
b(k)=double(t_value(yy,xx));
x1(k)=double(t_value(yyy,xxx));
y1(k)=double(t_value(yyyy,xxx));
z1(k)=double(t_value(yyy,xxxx));
b1(k)=double(t_value(yyyy,xxxx));
avg(k)=double(X(k)+Y(k)+Z(k)+b(k))/4;
avg1(k)=double(x1(k)+y1(k)+z1(k)+b1(k))/4;
end

サインインしてコメントする。

採用された回答

Rik
Rik 2018 年 7 月 6 日
ginput returns a decimal value, which you cannot use as indices. Use round to round your coordinates to integer values.
  8 件のコメント
deepika
deepika 2018 年 7 月 7 日
編集済み: Image Analyst 2018 年 7 月 7 日
Error in ima>pushbutton2_Callback (line 113)
X(k)=double(t_value(a,b));
In an assignment A(I) = B,
the number of elements in B and I must be the same.
I am getting this error.
Image Analyst
Image Analyst 2018 年 7 月 7 日
The comment was because you just posted code without any comment whatsoever and then you marked the question as "Accepted", meaning solved. Usually people will just say something like "Thanks - that fixed it" but you didn't say that, you just posted code. So that meant that (or might mean that), because you accepted the answer, your code must be the final code that is all working. Yet you didn't say that so that's why people were confused.
Now your latest comment seems to indicate that the problem is NOT solved yet.
Now since t_value is a2-D grayscale image, and (the poorly named) a and b are single integers (because you called ginput(1) and rounded them), then t_value(a, b) should be a value from the t_value array.
HOWEVER, you made a very common beginner mistake. Don't feel bad because, like I said, it's very common. You are indexing your arrays as t_value(x,y) instead of t_value(y, x). Now you should know that the first index of an array is the row index. Rows are y, NOT x. And the second value is the column index. Columns are x, NOT y. So you must refer to t_value(y, x) which, using your poorly named variables of a and b, is t_value(b, a) and NOT to t_value(a, b).

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 7 月 7 日
編集済み: Image Analyst 2018 年 7 月 7 日
You mixed up x,y with row,column. See my explanation in my comment under Rik's answer. It looks like you're using a as row (y), since it's the first index in t_value, and b as column (x) since b is the second index in t_value. To fix, simply replace this:
[a,b]=ginput(1);
with this:
[x1, y1] = ginput(1); % Let user click once then return the (x,y) coordinate he clicked on.
a = round(y1); % a = y1 = row.
b = round(x1); % b = x1 = column.
Better yet is to rename your variables a and b to something that makes sense, like column and row.
Also, please read this link so I don't have to keep fixing your code formatting.
  4 件のコメント
Image Analyst
Image Analyst 2018 年 7 月 7 日
See if this is what you want to do:
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in image.
% im=multibandread('paris.lan',[512,512,7],'uint8=>uint8',128,'bil','ieee-le');
% I don't have an image, so I'll create sample data.
numberOfBands = 2;
im = randi(255, 512, 512, numberOfBands);
% Show the first band to give the user something to draw on.
imshow(im(:, :, 1), []);
axis('on', 'image');
% Ask user to draw two pairs of points.
promptMessage = sprintf('Please locate the first pair of 2 points');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end
[xUser1, yUser1] = ginput(2);
hold on;
rows1 = round([xUser1(1), xUser1(1), xUser1(2), xUser1(2)])
columns1 = round([yUser1(1), yUser1(2), yUser1(1), yUser1(2)])
plot(rows1, columns1, 'r+', 'MarkerSize', 15, 'LineWidth', 2);
promptMessage = sprintf('Please locate the second pair of 2 points');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end
[xUser2, yUser2] = ginput(2);
rows2 = round([xUser2(1), xUser2(1), xUser2(2), xUser2(2)])
columns2 = round([yUser2(1), yUser2(2), yUser2(1), yUser2(2)])
plot(rows2, columns2, 'r+', 'MarkerSize', 15, 'LineWidth', 2);
hold off;
for band = 1 : numberOfBands
thisBand = im(:, :, band);
% Get the mean of the first set of 4 points.
mean1(band) = mean([thisBand(rows1(1), columns1(1)), ...
thisBand(rows1(2), columns1(2)), ...
thisBand(rows1(3), columns1(3)), ...
thisBand(rows1(4), columns1(4))]);
% Get the mean of the second set of 4 points.
mean2(band) = mean([thisBand(rows2(1), columns2(1)), ...
thisBand(rows2(2), columns2(2)), ...
thisBand(rows2(3), columns2(3)), ...
thisBand(rows2(4), columns2(4))]);
end
% Print out command window
mean1
mean2
z = xcorr2(mean1,(mean2))
% axes(handles.axes2);
figure;
plot(z);
grid on;
title('correlation of 2 signals');
deepika
deepika 2018 年 7 月 8 日
Here,I have attached two files,please check this and you will get to know the thing which i am in search for.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by