compiled matlab script where incorrect variables are passing
6 ビュー (過去 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!