Return textual stringdata without primes

Hi all,
I need to set up some strings with words, e.g.
C=['Horse' 'Apple' 'House' 'Van']
and then read in the different words again in another part of the program. However, if I read back these data , I get the word with primes, namely
C(1)='Horse'
and I need to get the words without the primes. I tried the character command, but then the answer is C(1)=H. Does anyone have a tip how to deal with this?
Thanks,
Ellen

6 件のコメント

Adam
Adam 2014 年 9 月 22 日
編集済み: Adam 2014 年 9 月 22 日
What do you want to do with them in a different part of the program? The primes just indicate that the collection of letters are a single string rather than 5 independent chars 'H', 'o', 'r', 's', 'e', but even as single chars you get the primes too to indicate a char rather than a variable or function name.
By the way, you should be using a cell array to have separate strings there as e.g.
C={'Horse' 'Apple' 'House' 'Van'}.
Your version will concatenate all those into a single string.
Stephen23
Stephen23 2014 年 9 月 22 日
編集済み: Stephen23 2014 年 9 月 22 日
Adam and dpb have already mentioned this, but watch the array type!
['Horse','Apple','House','Van']
ans = 'HorseAppleHouseVan'
{'Horse','Apple','House','Van'}
ans = {'Horse','Apple','House','Van'}
You probably want a cell array, if you want your strings to remain separate. Square brackets [] concatenate the strings together.
Ellen
Ellen 2014 年 9 月 23 日
Sorry guys, you're totally right and I meant indeed
C={'Horse','Apple','House','Van'}.
@Adam, I'm trying to create a script which I can use to automize writing out input files for a certain program. Therefore, I also need to insert names of certain minerals which should then be written in the file without primes (has something to do with a database it will be compared too).
Do you have any other ideas?
Thanks
Adam
Adam 2014 年 9 月 23 日
Functions like fprintf can write to file with names inserted. In general anything that writes to file with things dynamically included will not include quotes, they are just there for display purposes on the command line, workspace or variable editor
Ellen
Ellen 2014 年 9 月 24 日
When I apply a cell array as I described above and try to write it to file usinf frintf, I get the following error message:
Error using fprintf
Function is not defined for 'cell' inputs.
Apparently fprintf is not suitable for handling cell arrays.
Adam
Adam 2014 年 9 月 24 日
Can you give an example of exactly what you are trying to do? Are you trying to print:
'Horse Apple House Van'
to file?

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

回答 (1 件)

dpb
dpb 2014 年 9 月 22 日

1 投票

The "primes" (actually single quotes) are a figment of Matlab's display of cell strings--they aren't really a portion of the string itself.
As Adam notes, using a cell array will aid in using strings as then they cell contents are referenced instead of a single character and requiring 2D subscripts to reference a full string with character arrays.
A specific use also would be beneficial to amplifying this answer to a specific usage.

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

質問済み:

2014 年 9 月 22 日

コメント済み:

2014 年 9 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by