Horizontal concatenate in UItable table
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
chizom wornu
am 13 Jan. 2022
Kommentiert: chizom wornu
am 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 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), ' ')
Weitere Antworten (1)
Voss
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!