compiled matlab script where incorrect variables are passing
조회 수: 12 (최근 30일)
이전 댓글 표시
Hello,
I compiled a matlab script and am submitting it as a job in bash:
#!/bin/bash
# Generates and submits one SLURM job per slice, using the compiled
# TSE_multispinecho_EPG executable + MATLAB Runtime.
# ------------- USER‑ADJUSTABLE PARAMETERS --------------------------
PROJECT_DIR="/path/to/dir"
PROJECT_NAME="project"
SLICE=1
SUBJECT_CODE='subj1'
EXEC="$PROJECT_NAME/bin/TSE_multispinecho_EPG" # compiled executable
# -------------------------------------------------------------------
cat > "$JOB" <<EOF
#!/bin/bash
echo " slice : ${SLICE}"
"${EXEC}" "${PROJECT_DIR}" "${PROJECT_NAME}" "${SUBJECT_CODE}" "${SLICE}"
EOF
# ---- submit -----
sbatch "$JOB"
done
and then the beginning of the matlab functions looks like:
function TSE_multispinecho_EPG(project_directory, project_name, subject_code, slice);
%% TSE multi spin echo EPG
fprintf('slice within function: %d\n', slice);
and the slice number should be 1. When I run the bash command, I get '1', but when it gets the matlab part of the script I am getting '49'.
I cleared the cache, I made sure there weren't any extra slice variables causing renaming issues.
I can run the non-compiled command just fine, and then slice 1 will be printed correctly:
matlab -nodisplay -nosplash -r "TSE_multispinecho_EPG("/projectdir", "projectname", "subj01", "1")"
Any help would be much appreciated,
Thanks.
댓글 수: 0
채택된 답변
Star Strider
2025년 7월 8일
편집: Star Strider
2025년 7월 8일
The '49' is the ASCII code for '1' --
Q = double('1')
Mystery solved!
N = str2double('1')
It all depends on what you want to do, and the result you want.
EDIT -- (8 Jul 2025 at 19:26)
The problem may be here:
slice = '1';
fprintf('slice within function: %d\n', slice)
so one option could be --
fprintf('slice within function: %s\n', slice);
.
댓글 수: 3
추가 답변 (1개)
Walter Roberson
2025년 7월 8일
Note that
double('1')
so somehow you are getting a quoted 1 instead of a numeric 1.
I would suggest trying
matlab -nodisplay -nosplash -r "TSE_multispinecho_EPG("/projectdir", "projectname", "subj01", 1)"
댓글 수: 1
Walter Roberson
2025년 7월 8일
Ah, I did not notice that the executable was compiled. Compiled executables always receive their parameters as strings, never as actual numeric values.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!