Why can i not plot this?

1 Ansicht (letzte 30 Tage)
Emil Cramer
Emil Cramer am 28 Okt. 2015
Beantwortet: Thorsten am 28 Okt. 2015
i run this script clc
close
clear
%input%
Q=0.034;
T=0.0454;
S=0.0014;
t=365*24*60*60;
%equation%
for x=1:1:10;
y=(2.30*Q)/(4*pi*T)* log10((2.25*T)/(x.^2*S))+ (2.30*Q)/((4*pi*T))*log10(t);
end
plot(x,y)
but it does not show the plot on the figure

Antworten (2)

Rob Campbell
Rob Campbell am 28 Okt. 2015
Bearbeitet: Rob Campbell am 28 Okt. 2015
You can't plot anything because your code is full of mistakes. For starters, x and y are both just one number so you don't have an series of data points to plot. The loop is wrong. Your code is also very difficult to read and badly laid out and this is contributing to your confusion. If you correct those things, you will have an easier time figuring out what's wrong. Do the following:
1. Store your code in a .m file (ideally as a function: http://uk.mathworks.com/help/matlab/ref/function.html) and run that file.
2. Don't cram too much stuff on each line. One statement per line. Look at the code examples in the MATLAB docs and emulate that style.
3. Don't start with "clear". Blindly clearing the workspace isn't desirable and if you use a function then the variables are all local to it and will never need cleaning like this anyway.

Thorsten
Thorsten am 28 Okt. 2015
You don't need the for loop, but you have use ./ before (x.^2*S)):
x = 1:10; % no need to use :1:, 1 is the default increment
y=(2.30*Q)/(4*pi*T)* log10((2.25*T)./(x.^2*S))+ (2.30*Q)/((4*pi*T))*log10(t);
plot(x,y)

Kategorien

Mehr zu Help and Support finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by