how to make a trendline
9 views (last 30 days)
Show older comments
Good Day,
Please how do I add trendline to a certain straight line portion of a plot? I tried to follow tutorial from this link http://www.mathworks.com/matlabcentral/answers/57253-adding-trendline-to-a-plot , but i still didn't get a trendline.
Thanks
Best regards,
azalea
*this is my script
%Memulai semuanya dari nol~ clear; clc;
%Inisialisasi variabel-variabel Folder_msl_bulan = 'E:\GEODESI\SCRIPTSWEET\Data Pasut\PROGRAM\semarang\after QC\msl per bulan\'; %Tolong ini diubah sesuai isi hati Banyaknya_bulan = 12; Banyaknya_tahun = 13; %Diubah sesuai data yang ada mulai_bulan = 1; tahun = 1999; %Diubah juga tahun_akhir = tahun+Banyaknya_tahun;
%Cek apakah file kompilasi tersedia atau tidak Cek = exist(strcat(num2str(Folder_msl_bulan),'Kompilasi_msl_bulan.txt')) if Cek == 0 %File_kompilasi = save('Kompilasi_msl_bulan.txt', '-ascii'); fopen('Kompilasi_msl_bulan.txt','w+'); end kompilasi_msl_bulan = load('Kompilasi_msl_bulan.txt', '-ascii');
%Fungsi untuk menggabungkan kumpulan file teks menjadi satu for tahunan = tahun:tahun_akhir ; for(bulan=1:12); if bulan < 10 bulan = strcat('0', num2str(bulan)) ; end nama_file = strcat(num2str(Folder_msl_bulan),'semarang_',num2str(bulan),num2str(tahun),'.txt');
%Fungsi vertcat untuk menambahkan nilai ke dalam array
%kompilasi_msl_bulan. Nanti jadi isi filenya.
if exist(nama_file)
temp_msl_bulan = load(num2str(nama_file), '-ascii');
kompilasi_msl_bulan = vertcat(kompilasi_msl_bulan,temp_msl_bulan);
else
temp_msl_bulan = 0;
kompilasi_msl_bulan = vertcat(kompilasi_msl_bulan,temp_msl_bulan);
end
bulan = bulan + 1;
end
tahun = tahun + 1;
end
%Menyimpan hasil kompilasi dalam file teks dlmwrite('Kompilasi_msl_bulan.txt',kompilasi_msl_bulan,'delimiter','\t') type('kompilasi_msl_bulan.txt') fclose('all');
%Fungsi untuk membuat plot time series tanggalmulai = datenum('01-1999','mm-yyyy') tanggalakhir = datenum('12-2011','mm-yyyy') dt = linspace(tanggalmulai,tanggalakhir,length(kompilasi_msl_bulan));
%Fungsi menghitung regresi linear bdt = transpose(dt); Pf = polyfit(bdt,kompilasi_msl_bulan,1) Pf_Grafik = polyval(Pf, kompilasi_msl_bulan);
%Tampilkan plot %plot(dt,kompilasi_msl_bulan,'-',dt,Pf_Grafik) plot(dt,kompilasi_msl_bulan) datetick('x','yyyy','keepticks')
0 Comments
Answers (0)
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!