How to create letters, numbers and special characters

5 views (last 30 days)
Hi, I want to create a column like this:
{f (A,0) }
{f (A,1) }
{f (A,2) }
{f (A,3) }
{f (A,4) }
{f (A,5) }
{f (A,6) }
{f (A,7) }
{f (A,8) }
ect
Not sure how to tell MATLAB to do this... I guess should be easy, but I don't know how to mix together all the characters without the program gets crazy. I just need a clue.
Cheers,
Yan
  1 Comment
Stephen23
Stephen23 on 20 Jul 2016
"I want to create a column like this"
Where: In a file ? In a variable ? As a string ? A cell array of strings ? Variable names ? Field names ?

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 20 Jul 2016
Edited: Azzi Abdelmalek on 20 Jul 2016
out=arrayfun(@(x) sprintf('{f(A,%d)}',x),(0:8)','un',0)
Or
out=sprintf('{f(A,%d)}\n',(0:8)')

More Answers (1)

dpb
dpb on 20 Jul 2016
It'll have to be a string; Matlab can't store different types in the same array excepting as separate cells in a cell array.
Looks like you may be heading down a wrong path given the looks of the content of the question; what do you intend to do with this once you get it?
  2 Comments
Yan Vogel
Yan Vogel on 20 Jul 2016
Hi dbp, is just to write a txt file that gives commands to an instrument.
Don't worry, already done with LabVIEW. But still I would like to know.
Thanks,
Yan
dpb
dpb on 20 Jul 2016
OK, for output, it's ok; if were going to try to use to execute functions that way, "not so much".
As Azzi shows, except for writing a file use fprintf instead of sprintf to an open file handle from fopen

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!