0

(Edited) We have a string and want it to be repeated, say 5 times, namely from

  str = '%s ';

to

'%s %s %s %s %s '

Question 1: How to specify in the the format argument in textscan() function, to create a new line every 5 strings? I'm looking for something like [repmat('%s', 1, 5) '%*[^\n]'] (this doesn't work).

Question 2: the [data] = textscan(fid, [repmat('%s', 1, 5) '%*[^\n]'], 'Delimiter',{','},'headerLines', 1) currently gives me a 1xn cell - how to convert this into a mxn matrix?;

m7913d
  • 10,244
  • 7
  • 28
  • 56
fika_fika
  • 111
  • 1
  • 10

1 Answers1

1

Use repmat to repeat copies of an array. Pass 1 row and n columns to represent it as an array.

>>  str = '%s ';
>> repmat(str, 1, 5)

ans =

%s %s %s %s %s 
Devendra Lattu
  • 2,732
  • 2
  • 18
  • 27
  • I tried `repmat(str, 1, 5)` - however it doesn't wrap every 5 strings, please see my edited question. Thank you – fika_fika May 24 '17 at 20:26