Interp1 error when I moved the .m files into a different folder
Show older comments
Hello guys,
I got an interp1 error when I moved the .m files into a different folder at C:\Research\Interpolation. It still works well in the original folder (at C:\Users\Owner). What happened to that? There was no more message other than just "error" in Matlab.
Here is the script.
clear;
A=importdata('1.txt');
x = A(:,1);
v = A(:,2);
xq = 0:0.001:0.4;
figure
subplot(1,1,1)
vq1 = interp1(x,v,xq);
%plot(x,v,'o',xq,vq1,'-', 'Linewidth',3);
plot(x,v,'o','Linewidth',1); hold on;
plot(xq,vq1,'-', 'Linewidth',2);
%subplot(1,2,2)
%plot(xq,vq1,':.');
I would really appreciate it if you advise.
Thank you very much, Jin
7 Comments
There was no more message other than just "error" in Matlab
Really? If you got only "error", how do you know that it concerns interp1? What exactly are "the .m files", which are moved?
Use at least the debugger to find the failing line:
dbstop if error
Then run the code again. What do you observe?
Jinwon Shin
on 4 Jul 2017
"I copied "interp1.m" and "1.txt" in some folder."
"Something wrong with the use of interp1, although this works in the original folder?"
Nothing is wrong with interp1. But it will not work in any other folder other than the original one. That is how many/most MATLAB functions are: they cannot simply be copied and used anywhere that you want. Who told you that they can be?
Note that this also applies to your own code, once it is complicated enough to have local/private/nested/... functions then you will also realize that it makes no sense for any function to work wherever you happen to have put it. And then there is the MATLAB Search Path on top of that... and the license conditions...
Whoever told you that you can copy and use MATLAB functions anywhere was incorrect.
Jinwon Shin
on 4 Jul 2017
Edited: Jinwon Shin
on 4 Jul 2017
Jinwon Shin
on 4 Jul 2017
Edited: Jinwon Shin
on 4 Jul 2017
"is it true that the function "interp1" only applies to 1 file on a computer"
I am not sure what you mean by "applies". However interp1 can be called as many times you like, from as many scripts or functions as you wish... there is no limit. You have to ensure that those scripts/functions are on the MATLAB Search Path or the Current Directory.
If you are simply calling the interp1 function from a script/function in the current directory then interp1 will work. It is not totally clear what you have attempted so far.
You should not copy the code of interp1 anywhere: this will not work.
Answers (1)
The file interp1.m is located inside C:\Program Files\MATLAB\<MatlabVersion>\toolbox\matlab\polyfun\ . It must be stored there, because it uses subfunctions stored there and in the \private subfolder. interp1 will not run, if you copy it anwhere else. And even if it would run: There is no need to copy it. Leave it there. interp1 belongs to the Matlab installation and the "polyfun" folder is contained in Matlab's path, such that it is found by Matlab, if it is there.
Creating copies of your own files works reliably, as long as there are not multiple files with the same name inside Matlab's path.
Categories
Find more on 대용량 파일과 빅 데이터 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!