MATLAB Answers

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"

3 views (last 30 days)
AV on 4 Dec 2018
Commented: Cris LaPierre on 5 Dec 2018
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' )
Opts.subject = data{i}
Examplescript (Opts)
'testfiles.txt' contains:
Your help would be most welcome.


Bob Nbob
Bob Nbob on 4 Dec 2018
The error would seem to indicate that data is an empty array. Are you sure that the textscan command is properly scanning your file?

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 5 Dec 2018
Edited: Cris LaPierre on 5 Dec 2018
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:
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.


AV on 5 Dec 2018
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?

Sign in to comment.

Sign in to answer this question.



Translated by