Matlab turns char into double on cluster.
조회 수: 1 (최근 30일)
이전 댓글 표시
On the cluster I run
matlab -nodesktop -r "program 1" > program_1.out 2>&1
where the first lines of code in "program" look like this
function program(dtaset_id)
addpath(genpath('../..'))
if isempty(gcp('nocreate'))
parpool(maxNumCompThreads,'IdleTimeout', 300)
end
whos
load(strcat('dataset_', dtaset_id, '.mat'))
whos
dtaset_id = str2num(dtaset_id);
The strange thing is that the first "whos" reports "dtaset_id" to be a char, and the second whos reports it to be a double, causing an error in the last line.
How and why does this happen?
댓글 수: 0
채택된 답변
Voss
2022년 3월 30일
It may be that the mat file you load contains a variable called dtaset_id, which is a double. When you load the mat file that value overwrites the previous value of dtaset_id in your workspace.
Here I've attached a mat file with a double dtaset_id to demonstrate.
dtaset_id = '0';
whos('dtaset_id') % char
load(strcat('dataset_', dtaset_id, '.mat')) % overwrites dtaset_id with value from mat file
whos('dtaset_id') % now double
댓글 수: 2
Stephen23
2022년 4월 5일
This is one reason why it is recommended to always LOAD into an output variable:
S = load(..);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!