0

Greets all

I'm trying to output a character (a parenthesis) ')' to a file multiple times based on the length of a for loop. Example:

num1=23;
for i=1 length(array) 
     fprintf(fid,strcat(num2str(num1)),')')
end

output to the file would be 23))))))

the length of the array is 6 it should print 6 parenthesis )))))) to the file

I'm using octave/matlab on linux.

1 Answer 1

1

use repmat, for example: string = repmat(')',1,6) will produce )))))) and store it in variable string. And you can then append this string before fprintf into a file.

string = repmat(')',1,6)
fprintf(fid,[num2str(num1) string])

Btw, the string concatenate in matlab is done much nicer using: str = ['str1' 'str2' 'str3'] than strcat.

1
  • I found out you can also do it this way paraStr=[]; for zz=1:length(array_combined) paraStr=[paraStr ')']; end
    – Rick T
    Apr 6, 2013 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.