How do you remove single quotes around a cell?

5 ビュー (過去 30 日間)
Israel Yaghtin
Israel Yaghtin 2019 年 12 月 17 日
コメント済み: Walter Roberson 2019 年 12 月 30 日
I have an excel file containing keywords and what i want to have printed if that keyword is found in a string. A row looks something like this:
The first cell i have no trouble with, it works fine to search a string if Something is in it. The second cell I want to print Something with another word attached to it (SomethingSomewhere).
I've tried this using matrices instead of excel and it works perfectly. The issue with that is that its difficult to update keywords and the printed phrases, which I will need to too often for that to work.
My problem is excel saves the cells as '"Something"+c' (Including the single quotes) which defeats the purpose of the c variable. I cannot find any way to remove those single quotes around it. I wanted it saved as just "Something"+c and have the same result this would:
c="Somewhere";
x="Something"+c;
disp(x)
So that its output is SomethingSomewhere insead of "Something"+c.
My actual code is
for i=1:length(s) % s is the list of keywords
if contains(lstr,s(i)) == 1 % lstr is the string to search for keywords in
disp(sH(i)) % sH is the list of text to print
end
end
I found a few related posts, but none of the suggestions would work. For example I tried:
x=cell2mat(x)
%which would save the cell as '"Something"+c' (Including the single quotes)
x=strrep(x,'''','')
%Which i thought would remove those quotes but it didn't do anything
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 30 日
disp(sH{i})

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

回答 (1 件)

Abhilash Padma
Abhilash Padma 2019 年 12 月 30 日
You could use eval method in MATLAB to get the desired result. See the code below:
c="somewhere";
x='"Something"+c';
str=eval(x);
eval returns "somethingsomewhere" here.
Refer the following link for more information regarding eval method: https://in.mathworks.com/help/matlab/ref/eval.html
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 30 日
To me it appears to be an issue of displaying a cell array instead of the content of the cell array, so eval() would not be an appropriate solution.
eval() is almost never the appropriate solution for anything.

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

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by