Horizontal concatenate in UItable table
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
chizom wornu
le 13 Jan 2022
Commenté : chizom wornu
le 15 Jan 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 commentaires
Réponse acceptée
Walter Roberson
le 13 Jan 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), ' ')
Plus de réponses (1)
Voss
le 14 Jan 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 commentaires
Voir également
Catégories
En savoir plus sur Oceanography and Hydrology dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!