How to convert first cell value into zero

Hello
I have a array of numbers but the first cell is always a string like below. Is there way that I put ''0" instead of "theta\phi[rad]"? Then, I can do analysis :)
theta\phi[rad] 0 0.01 0.02
0 -0.15 -0.17 -0.14
0.2 0.19 -0.13 -0.11

 採用された回答

madhan ravi
madhan ravi 2020 年 9 月 25 日
編集済み: madhan ravi 2020 年 9 月 25 日

1 投票

cell_array(cellfun(@isstring, cell_array)) = {0}

7 件のコメント

Masoud Taleb
Masoud Taleb 2020 年 9 月 25 日
Thanks for the reponse. But it gives error! Should I give a value for cell_array?
Unrecognized function or variable 'cell_array'.
Error in Untitled (line 9)
cell_array(cellfun(@isstring, cell_array)) = {0}
madhan ravi
madhan ravi 2020 年 9 月 25 日
編集済み: madhan ravi 2020 年 9 月 25 日
Lol , cell_array is your values contained in a cell. It was just for illustration purposes.
If you just want the first cell to turn to zero. Then:
cell_array{1} = 0
Masoud Taleb
Masoud Taleb 2020 年 9 月 25 日
Unfortunately, this one does not work as well. It removes whole line!
madhan ravi
madhan ravi 2020 年 9 月 25 日
編集済み: madhan ravi 2020 年 9 月 25 日
What??! Upload your cell data as .mat file.
>> cell_array
cell_array =
3×4 cell array
{["theta\phi[rad]"]} {[ 0]} {[ 0.0100]} {[ 0.0200]}
{[ 0]} {[-0.1500]} {[-0.1700]} {[-0.1400]}
{[ 0.2000]} {[ 0.1900]} {[-0.1300]} {[-0.1100]}
>> cell_array{1} = 0
cell_array =
3×4 cell array
{[ 0]} {[ 0]} {[ 0.0100]} {[ 0.0200]}
{[ 0]} {[-0.1500]} {[-0.1700]} {[-0.1400]}
{[0.2000]} {[ 0.1900]} {[-0.1300]} {[-0.1100]}
>>
I have no idea about what you're talking about.
Masoud Taleb
Masoud Taleb 2020 年 9 月 25 日
OK, I do not know why your solution did not work for me but following one fixed the problem:
id = find(A{1}==',');
A{1}(1:id(1)-1) = '0';
madhan ravi
madhan ravi 2020 年 9 月 25 日
Obviously, the example you showed in your code and your last comment don’t contain the same data.
Masoud Taleb
Masoud Taleb 2020 年 9 月 25 日
I tried to simplify the example as my data file and main codes are very big and complicated to be uploaded. Meanwhile, it is possible that something was interfering it. Anyway, thanks for your reply and help :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by