Setting up and calculating using an array and ginput?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi I'm trying to get my code to calculate the difference between x, y coordinates held in an array and that acquired from ginput.
So I've got two x, y ginputs that I want to calculate the difference between the first and second pair of values in my array called "ActualValues", so in this case I'd like to get the difference between ginput1 and 124, 93 and the difference between ginput2 and 109, 77.
How do I do this?
I'm using the following code:
clear clc close all
Map=imread('Map.Jpg'); imshow(Map); hold on;
ActualValues = [124 93; 109 77; 125 83; 117 75; 122 80]
uiwait(msgbox('Choose Point A')); [x,y] = ginput(1); hline = plot(x,y,'r+', 'MarkerSize', 50);
A = ginput(1);
uiwait(msgbox('Choose Point B')); delete(hline); [x,y] = ginput(2); plot(x,y,'r+', 'MarkerSize', 50); B = ginput(1);
disp ('Values:') disp(A); disp(B);
Would really appreciate some help, although I understand a minus operation should do the trick, I'm having difficulty referencing the ginputs and the array accordingly.
Many Thanks.
채택된 답변
YT
2017년 12월 14일
편집: YT
2017년 12월 14일
Okay I did a little bit of adjustment to your code, but I think this is what you want to achieve
clear all;
close all;
Map = imread('Map.Jpg');
imshow(Map);
hold on;
uiwait(msgbox('Choose Point A'));
A = ginput(1);
hline = plot(A(1),A(2),'r+', 'MarkerSize', 50);
uiwait(msgbox('Choose Point B'));
delete(hline);
B = ginput(1);
plot(B(1),B(2),'r+', 'MarkerSize', 50);
disp(['Input 1; (x,y) = (' num2str(A(1)) ',' num2str(A(2)) ')'])
disp(['Input 2; (x,y) = (' num2str(B(1)) ',' num2str(B(2)) ')'])
diffBA = B-A; %difference B and A
disp(['Difference; (x,y) = (' num2str(diffBA(1)) ',' num2str(diffBA(2)) ')']);
I noticed that you didn't quite know how to display variables yet. I think you can figure it out yourself from the code above, but here's some clarification:
A(1) %x-coord. 1
A(2) %y-coord. 1
num2str(A(1)) %creates string from the numeric value for display purposes
disp(['...' here-your-string variable]) %use square brackets if you want to use variables in your disp()
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!