Graphing data stored in a function file

2 views (last 30 days)
Gabriella Dodd
Gabriella Dodd on 18 Sep 2019
Edited: dpb on 18 Sep 2019
Hello, I was given data in the form of a function and asked to call that data to be used in a graph but when I run the function only the x values print and I can't figure out how to call the y values
Here is the function file:
function [x, y] = hw02p2data()
% HW02P2DATA Input data for HW02 Problem 2
x = [2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 ...
131072 262144 524288 1048576];
y = [0.3679 0.7358 1.1036 1.4715 1.8394 2.2073 2.5752 2.9430 3.3109 3.6788 ...
4.0467 4.4146 4.7824 5.1503 5.5182 5.8861 6.2540 6.6218 6.9897 7.3576];
end
and here's the script I've come up with so far but obviously I am lost:
x=hw02p2data();
y=
plot(x,y,'._')
hold on
subplot(4,4,n)
semilogx(x,y)
semilogy(x,y)
loglog(x,y)
title('Comparison of Four Graphs with hw02p2data')
xlabel('X values')
ylabel('Y values')
grid on
legend('Linear', 'Semilogx', 'Semilogy', 'Loglog','location', 'best')
hold off
  2 Comments
rough93
rough93 on 18 Sep 2019
Edited: rough93 on 18 Sep 2019
Is the function file just creating the images?
If you're looking to compare the images to see where on image #1 the pixels from image#2 are coming from, I'd set it up something like this:
  • Set up a matrix of image #1 and #2 based on the color/shades (imread(img))
  • Set up a for loop for the height and width of the page to match each pixel from image #2 to image #1. You can speed this process up by implementing a if condition to move on early if a pixel doesn't immediately match.
  • Once all the pixels are match, have MATLAB return the values for what row and height the set matched up
On the other hand, if you're trying to have our code graph out the function, you'll need to call the function from your main code and graph it correctly. Take a look at how to write and call functions on the MATLAB tutorials site (Can't just give you homework answers :) )
It doesn't appear that you have called the function correctly from your main file.
dpb
dpb on 18 Sep 2019
Edited: dpb on 18 Sep 2019
Look at the function definition
function [x, y] = hw02p2data()
and you'll see it has two values defined to be returned.
You didn't provide a location for both in your call in your function so the second was thrown into the bit bucket.
Look at the documentation and examples for function to see about syntax for multiple return values (it's a pretty obvious extension but since this is homework we'll not just "give away the store" but provide hints/coaching :) ).

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!