How do I input my data in the correct format to overcome the problem "unable to peform assignment with 0 elements on the right hand side"

조회 수: 1 (최근 30일)
I am running matlab on an HPC and wish to create multiple array jobs changing the variable in Examplescript (Opts) to the name of the file in 'testfiles.txt'. I am unable to overcxome the problem "unable to peform assignment with 0 elements on the right hand side" when creating the variable Opts.subject = data{i}.
My code is:
i = getenv('PBS_ARRAY_INDEX')
index = str2num(i)
f = fopen( 'testfiles.txt' )
data = textscan(f, '%s' )
fclose(f)
Opts.subject = data{i}
Opts.subject
Examplescript (Opts)
'testfiles.txt' contains:
003_S_4136
006_S_4192
006_S_4546
Your help would be most welcome.
  댓글 수: 2
Bob Thompson
Bob Thompson 2018년 12월 4일
The error would seem to indicate that data is an empty array. Are you sure that the textscan command is properly scanning your file?
AV
AV 2018년 12월 5일
Thank you for your suggestion - it does seem to be scanning the file properly.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2018년 12월 5일
편집: Cris LaPierre 2018년 12월 5일
Your main issue is that, apparently, i is a char. At least you use str2num to convert it when creating index. You should therefore be using 'index' instead of 'i' in your assignment.
Opts.subject = data{index}
However, there is, I suspect, another issue.
data is a 1x1 cell.
data{1} is a 3×1 cell array:
{'003_S_4136'}
{'006_S_4192'}
{'006_S_4546'}
data{1}{index} (where index = 1) is '003_S_4136'.
Your code makes me think you want to pull out the first subject id, not all 3 at once.
  댓글 수: 2
AV
AV 2018년 12월 5일
Thank you - agreed to use index instead. You are correct about the second issue. Is there a way to reformat this to run all 3 at once?
Cris LaPierre
Cris LaPierre 2018년 12월 5일
Maybe. It all depends on what your code does. What does running all 3 at once mean?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Application Deployment에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by