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

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)

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

i already did it how you have it in your responce and still didnt work...maybe there is something else wrong in my program
Jon
Jon on 10 Mar 2020
Edited: Jon on 10 Mar 2020
Did you run the exact code I attached in my post? Please copy it into a script and run it
I would be very surprised if this gave errors. If it does please post (copy and paste the exact errors it gives)
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.
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.

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

i shared an image above of what i have so far..
Sorry, I don't know Octave and how it might differ from MATLAB. For example, if it doesn't have the inputdlg() function I showed you how to use.
Maybe you can ask in an Octave forum instead of here in the MATLAB Answers forum.
oh i see. i was told from my instructer that matlab and octave are the same thing..
I don't think so, exactly. At best Octave is behind a version or two. Can you use inputdlg() like I showed you?
not sure if i did it corretly but thats what i have down now
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.

Categories

Asked:

on 10 Mar 2020

Commented:

on 11 Mar 2020

Community Treasure Hunt

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

Start Hunting!