point slope form on matlab? how should it be inputted?

21 views (last 30 days)
Im working on a basic program but cant figure out in what form i should have the point slope form equation on the editor so that i dont get errors there. I tried it this way y= m (x-x1) + y1 but it doesn'y work.

Answers (2)

Jon
Jon on 10 Mar 2020
I don't think there is anything wrong with you formula, I'm guessing you didn't define your x1,y1, m, and x properly. Try something like this
% for example
y1 = 1; % y coordinate of base point
x1 = 2;% x coordinate of base point
m = 3; % slope
% define some x values between zero and 10
x = linspace(0,10,50);
% evalualte the point slope formulae
y = m*(x-x1) + y1;
% plot the fitted line
plot(x1,y1,'o',x,y)
  5 Comments
Reila01
Reila01 on 10 Mar 2020
i copied and pasted exactly what you gave me and i run it but i only get a graph pop up in a separate window.
Jon
Jon on 11 Mar 2020
I guess I did not understand what your question was. That's all the script does, it defines the point slope parameters and then makes a graph of the results which is what I thought you wanted to do. I'm guessing from the ongoing thread with @Image Analyst that your issues are not with how to implement the point slope formula in MATLAB but how to ask the user for the parameters of the point slope formula. As it looks like you are deep into this with @Image Analyst I will let you follow up there.

Sign in to comment.


Image Analyst
Image Analyst on 10 Mar 2020
Are you using your own GUI built with GUIDE or App Designer, or are you using inputdlg(), or (worst case) using input()?
In the meantime, here's some code to ask the user for two numbers using inputdlg(). Adapt as needed.
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end
  7 Comments
Reila01
Reila01 on 10 Mar 2020
not sure if i did it corretly but thats what i have down now
Image Analyst
Image Analyst on 11 Mar 2020
Do you want to assign the values in code, as your line 6-9, or do you want to ask the user via a popup dialog box like the code I showed you?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!