DonCorleoneM
DonCorleoneM

Reputation: 25

Load Argument must contain a string, strcat MATLAB

Hi I'm using this code in MATLAB

var1=get(handles.listbox1,'String');
var2=get(handles.listbox1,'Value');
var3=var1(var2);
set(handles.text16,'String',var3)
var4 = strcat('C:\Users\Mehdi BEJAOUI\Desktop\TestL\MATLAB_temp\HBM\HBM\',var3,'')
load(var4) ;

When I run the programme I get this error : Error using load Argument must contain a string.

but when I use load('C:\Users\Mehdi BEJAOUI\Desktop\TestL\MATLAB_temp\HBM\HBM\NameOfAnyFile') , itw works perfectly

Upvotes: 1

Views: 1727

Answers (1)

RPM
RPM

Reputation: 1769

When you run it what is var4 set to? I suspect, looking at this, that var1 returns a cell array. var3 is then set to a 1x1 cell array. With the strcat function you are then concatenating a cell array and a string, and Matlab might consider the cell array to be the lowest common denominator, setting var4 to a cell array, which load() does not like. This would not happen if you just typed out the full string.

In short, I believe using curly brackets here var3 = var{var2} might solve your problem.

Upvotes: 1

Related Questions