Cant use Excel names to fprintf?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i´m trying to fprintf strings that display (names, height and weight) of all the persons in an excel document. But since fprintf can´t use 'cell' inputs i cant continue. I´ve tried to change the cells into 'doubles' and 'char' arrays but nothing seems to work?
Can anyone help?
gogn = readtable("Book1.xlsx", "VariableNamingRule","preserve");
gogn.Properties.VariableNames;
[tblB,index] = sortrows(gogn);
fname = tblB.Fornafn; % first name
lname = tblB.Eftirnafn;% last name
weight = tblB.("[pund]");% pounds
height = floor(tblB.("[foot.inch]"));%feets
for k = height
meters = k/3.2808; %chage to meters
fprintf('%s %s is %.2f meters and %.2f pounds./n',fname,lname,meters,weight)
end
0 Kommentare
Akzeptierte Antwort
Voss
am 4 Nov. 2022
gogn = readtable("Book1.xlsx", "VariableNamingRule","preserve");
[tblB,index] = sortrows(gogn);
fname = tblB.Fornafn; % first name
lname = tblB.Eftirnafn;% last name
weight = tblB.("[pund]");% pounds
height = floor(tblB.("[foot.inch]"));%feets
meters = height/3.2808; %change to meters
for k = 1:numel(meters)
fprintf('%s %s is %.2f meters and %.2f pounds.\n',fname{k},lname{k},meters(k),weight(k))
end
Weitere Antworten (2)
Fangjun Jiang
am 4 Nov. 2022
see this example
fname={'abc'};
fprintf('%s',fname)
fprintf('%s',fname{1})
0 Kommentare
Steven Lord
am 4 Nov. 2022
You can convert your cell array into a string array (assuming it contains text data) using string or into a numeric array (assuming the elements are compatibly sized) using cell2mat.
c = {'Benjamin', 'Steve', 'Cleve'}
s = string(c)
fprintf('%s\n', s)
dc = {1, 2, 3, 4}
d = cell2mat(dc)
fprintf('%d\n', d)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets 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!