Info

This question is closed. Reopen it to edit or answer.

when i run a code i get the following error message and i'm not sure why. an anyone make suggestions?

1 view (last 30 days)
Error in ==> run_code at 25
raman3 =
BackgroundSubtractionBerger(filename_in,filename_background,filename_out,filename_background_out)
??? Undefined function or variable 'base_filename_in'.
Error in ==> BackgroundSubtractionBerger at 41
fid = fopen(base_filename_in,'r'); % insert name of cell file
Error in ==> run_code at 25
raman3 =
BackgroundSubtractionBerger(filename_in,filename_background,filename_out,filename_background_out)
The Raman3 function runs perfectly on it's own but it's giving this error when run in conjunction with the loop 'runcode'
bare in mind i'm a novice at matlab coding. also the code is being used to open .txt files

Answers (1)

Image Analyst
Image Analyst on 18 Jul 2014
You're using base_filename_in in
fid = fopen(base_filename_in,'r');
when you should probably be using filename_in
fid = fopen(filename_in,'r');
Though I'm not really sure which are base filenames (no path/folder prepended) and which are full file names (path/folder prepended). You should probably make that more robust.
  2 Comments
gordon
gordon on 18 Jul 2014
Edited: gordon on 18 Jul 2014
This is the first few line of the loop
"base_filename = 'C:\Users\User\Desktop\cancer research project\raman data\CD34+ samples\sample2';
final = 40;
close all;
a = 0;
%BASE FILENAMES
base_filename_in = 'healthy2_'; base_filename_background = 'background2_01.txt'; base_filename_background_out = 'CR_healthy2_'; base_filename_out='CR_healthy2_';
for (b=1:1:9)
%make file names
b; filename_in = strcat(base_filename_in,int2str(a),int2str(b),'.txt');
filename_out = strcat(base_filename_out,int2str(a),int2str(b),'raman2.txt');
filename_background = base_filename_background;
filename_background_out = strcat(base_filename_background_out,int2str(a),int2str(b),'minbkdatast.txt');
raman3 = BackgroundSubtractionBerger(filename_in,filename_background,filename_out,filename_background_out)
end"
It has worked for previous data sets so i am unsure what's going on. I taught myself matlab coding so forgive me if it's all over the place
Also the file names are "healthy2_01.txt, healthy2_02.txt" etc.
Image Analyst
Image Analyst on 18 Jul 2014
OK, but inside the function you're using "base_filename_in" not filename_in, which is listed in the input argument list when you actually define the function (not call it). You do know that the main calling program can have different names for the variables when you call a function than those used when the function is defined, right? And just because you have base_filename_in in your main routine does not mean you have it in the function. You have to look at what name matches up with it in the argument list of the function. If you pass in in1 as the first argument, but your function calls it inputVariable1, then everywhere in your function it must be called inputVariable1 and where that occurs, it will use the values of in1 that you passed in.

Community Treasure Hunt

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

Start Hunting!