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?
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
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 Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2021년 8월 11일

편집:

2021년 8월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by