Problem using a text file
Good evening. I have a matlab program (I'm not the author but I must modify it). In the original source (See attachment) files are opened by the code
load 'dia_221_2_0_2.txt'; %spettro diamante in diffrazione load 'hopg_220_4_0_2.txt'; %spettro grafite in diffrazione campione 2 ex 'hopg_220_4_0_2.txt' load 'c60_217_0_0_2.txt'; load 'piro_216_0_0_2.txt'; % spettro PIROVALVOLA in diffrazione
later the data files are used in:
ck(j) =piro_216_0_0_2(j);% sample 9 ora 7 (il più grafitico) ckdiadiff(j) =dia_221_2_0_2(j);%% spettro del diamante in diffrazione
ckgradiff(j) = hopg_220_4_0_2(j);%% spettro della grafite in diffrazione
c60diff(j)= c60_217_0_0_2(j); %%% spettro c60 in diffrazione
Now I want to change the program so that it the user can write the data file name. I tried to do it, but I couldn't! I just tried for one file (for example the dia_221_2_0_2.txt file) I first defined the variable:
global diamdiff
later I wrote
diamdiff=input('Diamond spectrum name= ');
[fid msg]=fopen(diamdiff,'r');instead of
load 'dia_221_2_0_2.txt'; %spettro diamante in diffrazione
and lastly I wrote
ckdiadiff(j) =diamdiff(j);%% spettro del diamante in diffrazione
instead of
ckdiadiff(j) =dia_221_2_0_2(j);%% spettro del diamante in diffrazione
Unfortunately, running the program Matlab gives this error:
Index exceeds matrix dimensions.
Error in sp2sp3diff_Titantah (line 69)
ckdiadiff(j) =diamdiff(j);%% spettro del diamante in diffrazione
Please, can you help me?
I think the reason is that in the original program, in the line
ckdiadiff(j) =dia_221_2_0_2(j);%% spettro del diamante in diffrazione
there is just the name of the file WITHOUT the extensions! In my code
ckdiadiff(j) =dia_221_2_0_2(j);%% spettro del diamante in diffrazione
the variable dia_221_2_0_2 maybe is read not just like the name, but like name and extension of file! Maybe I can resolve assigning the name of the file (Without extension) to a new variable and putting this variable in this line
ckdiadiff(j) =variable(j);%% spettro del diamante in diffrazione
But what script can I use to assign the name of the file (without extension) to a variable?
Thank you
Answers (2)
1 Comment
Categories
Find more on Environment and Settings 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!