Home Messages Index
[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index

Re: Newbie fopen() question

Cingulate wrote:

> This might be a really simple question but fopen doesn't seem to
> like
> the concatenated string I'm passing it and spits out an "Invalid
> filename" error when in fact the filename does exist. (I tried
> opening
> it explicitly from the command prompt and it worked.)
> Can anybody tell me what I may be doing wrong ?
> Thanks.

> datadirstem ='/xxx/yyy/';
> subjs = {'a';'b';'c';}
> for i=1:3
>
> fname = strcat(datadirstem, subjs(i),'suffix')
>
> fid = fopen(fname, 'r');
>
> end

The problem is that you're not passing fopen a string; you're passing
a cell array. In your strcat command, you include two strings
(datadirstem and 'suffix') and one cell array (subjs(i)), so the
result is a cell array. Replace that line with

fname = [datadirstem, subjs{i}, 'suffix'];

-Kelly

[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index