Horizontal concatenate in UItable table
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
chizom wornu
el 13 de En. de 2022
Comentada: chizom wornu
el 15 de En. de 2022
Hello, I have a code that uploads excel data into UItable. I want to concatenate the rows of the table however, some of the output are special charaters. Please how do i get it right. Below is my code and the results.
Table Data
Output Data
This is my code
oldData = get(GUI.RetailerStockList,'Data')
for i=1:size(oldData,1)
oldData(i)={horzcat(oldData{i,:})};
end
oldData(:,2:size(oldData,2))=[]
0 comentarios
Respuesta aceptada
Walter Roberson
el 13 de En. de 2022
oldData(i)={horzcat(oldData{i,:})};
Let us look at what that is being asked to do for i == 1:
oldData(1,:) = {'bacon rashers', 250, 'g', 738120, 'Use By', 0}
You horzcat() those, so you are asking for
['bacon rashers', 250, 'g', 738120, 'Use By', 0]
What is the rule when concatenating character vectors and numeric values?
TYPE | character | integer | single | double | logical
character | character | character | character | character | invalid
So when you [] together a character vector and a numeric value, the result is a character vector. This is not accomplished by formatting the number as text: this is accomplished by taking char() of the numeric value, looking up the underlying character codes as characters .
So the above line is equivalent to
['bacon rashers', char(250), 'g', char(738120), 'Use By', char(0)]
You should consider switching:
C = {"bacon rashers", 250, "g", 738120, "Use By", 0}
strjoin(string(C), ' ')
Más respuestas (1)
Voss
el 14 de En. de 2022
c = readcell('input.xlsx');
c(1,:) = [];
idx = ~cellfun(@ischar,c);
c(idx) = cellfun(@num2str,c(idx),'UniformOutput',false)
c_new = cell(size(c,1),1);
for i = 1:size(c,2)
c_new = strcat(c_new,c(:,i),{' '});
end
display(c_new);
0 comentarios
Ver también
Categorías
Más información sobre Oceanography and Hydrology en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!