A = 14×1 cell array
{'0.1' }
{'0.2' }
{'1' }
{'1.1' }
{'1.2.3' }
{'1.2.3.1'}
output i want like this
A =
0.1
0.2
1
1.1
1.2.3
1.2.3.1

2 件のコメント

Rik
Rik 2021 年 8 月 11 日
What is flagging your own question going to achieve? You can post comments and even edit your question to clarify it.

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

 採用された回答

the cyclist
the cyclist 2021 年 8 月 11 日

0 投票

Here is one way:
A = {'0.2','1'}
A = 1×2 cell array
{'0.2'} {'1'}
output = cellfun(@str2num,A)
output = 1×2
0.2000 1.0000

8 件のコメント

Divyesh pandav
Divyesh pandav 2021 年 8 月 11 日
A = {'0.2','1.2.3'}
output = cellfun(@str2num,A)
Error using cellfun
Non-scalar in Uniform output, at index 2, output 1.
Set 'UniformOutput' to false.
the cyclist
the cyclist 2021 年 8 月 11 日
編集済み: the cyclist 2021 年 8 月 11 日
Oh, sorry. Missed that you had non-numbers in there.
1.2.3.1 is not a number, and cannot be stored as anything other than a string or character array.
What are you trying to do as a next step, where you want "only the number"? To be clear, the single quotes that MATLAB puts around each character array are not part of the array itself. It is only a notation.
Divyesh pandav
Divyesh pandav 2021 年 8 月 11 日
編集済み: Divyesh pandav 2021 年 8 月 12 日
i want passing this value in this query
query = strcat('SELECT sum(abc) from abc = ''',A ,''' ORDER BY abc ');
the cyclist
the cyclist 2021 年 8 月 11 日
編集済み: the cyclist 2021 年 8 月 11 日
Hm. It seems to me that you actually want a string -- not a MATLAB numeric value -- in order to be able to build the query. Can you post an example of what the query would be if you were using just SQL (and not creating it in MATLAB)? Don't include ANY additional quotes that would not be in the SQL. For example, I am guessing it is something like
====================================================================
SELECT SUM(abc.time_taken) FROM abc WHERE abc.que_toc_no = '1.2.3.1'
====================================================================
Then maybe we can see how to construct that sequence of characters, using the contents of the cell array.
Divyesh pandav
Divyesh pandav 2021 年 8 月 12 日
yes, you are right , how to get this value in cell array?
Rik
Rik 2021 年 8 月 12 日
A = {'0.2','1.2.3'};
query = cellfun(@(x) strcat('SELECT sum(abc .time_taken) from abc.que_toc_no = ''',x ,''' ORDER BY abc '),...
A,'UniformOutput',false);
query.'
ans = 2×1 cell array
{'SELECT sum(abc .time_taken) from abc.que_toc_no = '0.2' ORDER BY abc' } {'SELECT sum(abc .time_taken) from abc.que_toc_no = '1.2.3' ORDER BY abc'}
Divyesh pandav
Divyesh pandav 2021 年 8 月 12 日
thank you so much
Stephen23
Stephen23 2021 年 8 月 12 日
No need for CELLFUN when STRCAT can handle that cell array by itself:
A = {'0.2','1.2.3'};
B = strcat('SELECT sum(abc .time_taken) from abc.que_toc_no = ''',A(:),''' ORDER BY abc')
B = 2×1 cell array
{'SELECT sum(abc .time_taken) from abc.que_toc_no = '0.2' ORDER BY abc' } {'SELECT sum(abc .time_taken) from abc.que_toc_no = '1.2.3' ORDER BY abc'}

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by