I am a matlab beginner.You are required to change the part of the directory reference so that someone else can read the code and use your PC.
I'd like to read the folders in a certain directory one by one.The folder name is a data ID, and the ID consists of "W", "01-16", and "d1 or d3" such as "W01_d1".
There is a folder called "condition1" in this ID folder that contains files for software loading.
mindir=['E:\HDD'filesepID];
spmdir_tmp = which('software');
spmdir=spmdir_tmp(1:end-5);
NBdir = {[mainidir, '\conditon1']};
As for filesep in line 1, I understand if it corresponds to the file separator of the current platform ( ?ID's W01 part?), but I don't actually read the ID folder and I don't know exactly how far I'm referring to this code.
If you do not read the folder name of the ID, it is determined by the output of "E:\HDD\condition1" when you turn the source.
I would appreciate it if you could let me know what you noticed.Thank you for your cooperation.
matlab
MATLAB scripts are free to browse variables in the workspace (like global variables in other languages).For example, suppose you have a script called setNBdir.m
:
%setNBdir.m
NBdir = ['test' filesep ID ];
In the command window, you can first place a value in the ID
and then invoke this script to create a variable called NBdir
in your workspace.
>>ID='hoge';
>>setNBdir
>>NBdir
NBdir=
'test\hoge'
You can also call from another script.
%callNBdir.m
IDs = {'A', 'BB', 'CCC'};
for i=1:numel(IDs)
ID = IDs {i};
setNBdir
disp(NBdir)
end
Running this script (callNBdir.m)
>>callNBdir
test\A
test\BB
test\CCC
The result is
If you're using the variable ID
in your script without defining it, it's probably a script that assumes you've prepared the ID
in advance (if it's a script for others to use, you'd better create a function that doesn't require workspace).
In conclusion, prepare the contents of the ID
yourself.
© 2024 OneMinuteCode. All rights reserved.