Hi I was coding when I had this error:
Time_msg_match = string(Time_msg_match);
Error using string
Conversion from cell failed. Element 61649 must be convertible to a string scalar.
>> Time_msg_match(61649)
ans =
1×1 cell array
{2×1 double}
How can I concadenate this 2x1 double?
I wrote:
Time_msg_match1 = num2str(cat(1, Time_msg_match{:}));
But the result is not what I wanted. Thanks in advance

 Respuesta aceptada

Image Analyst
Image Analyst el 23 de Oct. de 2021
Try this to create 2 separate variables out of that 1x2 cell array
Time_msg_match1 = Time_msg_match{1};
Time_msg_match2 = Time_msg_match{2};

6 comentarios

flashpode
flashpode el 23 de Oct. de 2021
I was not meant to do that. I wanted:
Time_msg_match is a 311282x1 cell where some of the cells have (2x1 double or 3x1 double). I want them to split¿? in diferent cells so the total number of cells of variable Time_msg_match increase.
Image Analyst
Image Analyst el 23 de Oct. de 2021
Attach Time_msg_match in a .mat file so I can try some things. Come on, make it easy for me to help you, not hard.
flashpode
flashpode el 25 de Oct. de 2021
Here it is. Sorry for the delay
@vicente Noguer, that is a cell array of 311,472 rows and one column. Inside each of those cells is a single scalar number. I'm not sure what to do with this since the cells do not contain either a 2x1 or 3x1 double array. Try this:
s = load('Time_msg_match.mat')
Time_msg_match = s.Time_msg_match;
numCells = numel(Time_msg_match)
% Allocate a second array. Make it a cell array, but it really probably doesn't have to be.
% Time_msg_matchCA = cell(numCells+10000, 1); % More than needed - we'll crop later.
% Allocate a second array. A double array since we don't need it to be a cell array.
Time_msg_match2 = zeros(numCells+10000, 1); % More than needed - we'll crop later.
vector2Index = 1;
for k = 1 : numCells
len = length(Time_msg_match{k});
if len == 1
Time_msg_match2(vector2Index) = Time_msg_match{k}; % Assign to double array.
% Time_msg_matchCA{vector2Index} = Time_msg_match{k}; % Assign to cell array.
vector2Index = vector2Index + 1;
else
fprintf('Row %d has %d elements in it.\n', k, length(Time_msg_match{k}));
for k2 = 1 : len
thisVector = Time_msg_match{k};
Time_msg_match2(vector2Index) = thisVector(k2);
% Time_msg_matchCA{vector2Index} = thisVector(k2);
vector2Index = vector2Index + 1;
end
end
end
% Crop off unused elements.
if vector2Index < numCells
Time_msg_match2 = Time_msg_match2(1 : vector2Index - 1);
% Time_msg_matchCA = Time_msg_matchCA(1 : vector2Index - 1);
end
fprintf('Original Time_msg_match had %d rows.\n', numCells)
fprintf('Afterwards Time_msg_match had %d rows.\n', numel(Time_msg_match2))
I put the results into a double column vector Time_msg_match2. If you really need a cell array, like some other function is expecting a cell array not a double array, then uncomment the lines mentioning Time_msg_matchCA and comment out the ones mentioning Time_msg_match2.
I did not get what you tried to do but look what I have when I code
>> Time_msg_match = Time_msg_match';
>> Time_msg_match = string(Time_msg_match)
Error using string
Conversion from cell failed. Element 61649 must be convertible to a string scalar.
>> Time_msg_match(61649)
ans =
1×1 cell array
{2×1 double}
flashpode
flashpode el 25 de Oct. de 2021
But I have deleted this line and it has worked so it is resolved. Thank you. Now I want to use this to index a duration array but I am gonna look by myself to do this. Once again thank you!!!!!

Iniciar sesión para comentar.

Más respuestas (1)

Rik
Rik el 23 de Oct. de 2021
It looks like this is what you want:
x=Time_msg_match(61649);
x=x{1};

7 comentarios

flashpode
flashpode el 23 de Oct. de 2021
But this can be save in the same variable as Time_msg_match? Cause your are saving it in variable X
Since this is a basic Matlab syntax question, I'm wondering if you are asking the question you want the answer to. But if so: of course you can:
Time_msg_match=Time_msg_match(61649);
Time_msg_match=Time_msg_match{1};
Maybe you should have a more explicit explanation of what goal you want to reach and what data you're starting with.
flashpode
flashpode el 23 de Oct. de 2021
Okay lets see Time_msg_match is a 311282x1 cell where some of the cells have (2x1 double or 3x1 double). I want them to split¿? in diferent cells so the total number of cells of variable Time_msg_match increase.
I had the same problem with strings and in a post they aswer it. The question is the same but with different data. Here is the post I made:
Hope it helps to understand my problem!!
So something like this?
a={{1,2},3,4};
[a{:}]
ans = 1×4 cell array
{[1]} {[2]} {[3]} {[4]}
flashpode
flashpode el 24 de Oct. de 2021
well a={{1,2} That not a cell it has to be a double,3,4};
Image Analyst
Image Analyst el 24 de Oct. de 2021
@vicente Noguer, did you overlook my request?
Also, a specific numerical example using the first 2 or 3 rows of your cell array would be helpful. Help us to help you.
Rik
Rik el 24 de Oct. de 2021
You are ignoring the advice that Image Analyst is giving you. That is not smart.
Also, did you try making a it a double array instead of a cell? You will notice that my code will still do something usefull. It brings you only a single step away from the array you need.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Oct. de 2021

Comentada:

el 25 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by