How to write a file with strings and numbers

2 ビュー (過去 30 日間)
Samuel
Samuel 2013 年 7 月 23 日
I would like to write an output file with all the information of variables and strings of my input files and values.
For example:
FILENAME = 'ASDF.txt'
XVALUE = 123
YVALUE = 123
Reading in forums, I was able to create a matrix with strings and numbers, which is not quite what I would like...
Any help will be appreciated. Thanks!
  1 件のコメント
Jan
Jan 2013 年 7 月 23 日
It is not clear yet, how your input data look like. Is e.g. "XVALUE" stored as a string or should this be taken dynamically from the name of the variable?

サインインしてコメントする。

回答 (1 件)

dpb
dpb 2013 年 7 月 23 日
If the names are known and fixed, it's simple enough to just write them literally. If, otoh, it's more general than that you can encapsulate the write in a function inside of which you can use
inputname()
to retrieve the variable names of the calling argument(s) as strings that can then be written to the file.
doc inputname % for more details
Or, alternatively, use named structure fields where the names are dynamically created and hence known.
  2 件のコメント
Samuel
Samuel 2013 年 7 月 23 日
Thanks for the help. The part I am having trouble with is writing these string and values to a *.txt file, which consists of both strings and numbers.
I am working on writing the strings/values using 'fid' and 'fprintf'...
dpb
dpb 2013 年 7 月 23 日
編集済み: dpb 2013 年 7 月 23 日
Post a short sample piece of code/data where you're having trouble, specifically...also expound on your initial request--is that a fixed format for the file or are the strings to be written contained in variables and if so, what type--cells or character strings, etc., etc., etc., ... or are you actually trying to get variable names from workspace, what????
We only know what you tell us...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by