Getting error in PARFOR in MATLAB
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I was using PARFOR to create 80 files using MATLAB. The code is as below:
function [t,ele_num_pipe,support_nodes] = write_kfile_pipe_final2( P, inundation_depth, D , A, L, sigy , flow_direction, sim_num )
However, I am getting an error message in the follwoing line of write_kfile_pipe_final2.m function.
fileID = fopen('shell_',num2str(sim_num),'.txt','w');
Error: "INVALID PERMISSION"
I found some tips to solve this in mathworks (Invalid permission error with fopen()). The invalid permission error was resolved by modifying the line as below:
name = 'shell_',num2str(sim_num),'.txt';
fileID = fopen(name,'w');
However, I am now getting another error message in the following line:
shell_ele = load('shell_',num2str(sim_num),'.txt');
Error message:
"File shell_ is in use by another process or thread. You should be able to load data once the other process or thread has released the file."
Can anyone help me in this, please?
1 Kommentar
Stephen23
am 5 Sep. 2023
Bearbeitet: Stephen23
am 5 Sep. 2023
"Can anyone help me in this, please?"
Both of the errors have exactly the same cause. The FOPEN documentation states that its 1st argument must be a filename, and its optional 2nd argument the permission. Lets take a look at how you called it:
fileID = fopen('shell_',num2str(sim_num),'.txt','w');
% ^^^^^^^^ 1st: part of filename
% ^^^^^^^^^^^^^^^^ 2nd: part of filename
% ^^^^^^ 3rd: part of filename
% ^^^ 4th: permission
You then did exactly the same thing again when you called LOAD. The LOAD documentation states that its 1st argument must be the filename. This is how you called it:
shell_ele = load('shell_',num2str(sim_num),'.txt');
% ^^^^^^^^ 1st: part of filename
% ^^^^^^^^^^^^^^^^ 2nd: part of filename
% ^^^^^^ 3rd: part of filename
You need to follow the syntaxes given in the documentation: if the documentation states that the filename is one input then you need to provide it as one input, not as three inputs.
Antworten (1)
Matt J
am 4 Sep. 2023
It looks like you are trying to read a file (with load()) while it's being written to. Perhaps you mean to do the reading first? Or perhaps you have finished writing to the file and need to close it? If the latter, see fclose.
8 Kommentare
Walter Roberson
am 5 Sep. 2023
fileID = fopen('shell_',num2str(sim_num),'.txt','w');
means that the character vector 'shell_' should be passed as the first parameter; that the numeric value sim_num should be converted to character representation of decimal and passed as the second parameter; that the character vector '.txt' should be passed as the third parameter, and the character vector 'w' should be passed as the 4th parameter
name = 'shell_',num2str(sim_num),'.txt';
That means that the character vector 'shell_' should be assigned to the variable name and then the result should be displayed like
name =
'shell'
After that, the numeric value sim_num should be converted to character representation of decimal, and then the result should be displayed like
ans =
'2'
and then the character vector '.txt' should be stored in the internal variable named ans and nothing should be displayed.
If you want to combine character vectors into a single character vector, you need to use [] or strcat() -- or use string objects with the + method of string() objects
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!