Concatenating Mixed numbers looses the decimal places

2 Ansichten (letzte 30 Tage)
Jason
Jason am 25 Sep. 2024
Kommentiert: Jason am 25 Sep. 2024
Hi, I have some numbers that I want to concatenate and add to a uitable. I've noticed that although the individual numbers have decimal places, the concatenation seems to remove the decimal values.
n
MaxI
MinI
medianMaxIntensity
Hlg
fwhm2D
Bren
A=[n,MaxI,MinI,medianMaxIntensity, Hlg,Bren,fwhm2D]
%-----------------------------------------------------------
n =
405
MaxI =
uint16
168
MinI =
uint16
36
medianMaxIntensity =
126
Hlg =
3.7750
fwhm2D =
4.1606
Bren =
56.1112
A =
405 168 36 126 4 56 4
How can I retain the decimal numbers (I only want 2 decimal places, so will use:)
uit.ColumnFormat= {'bank','bank','bank','bank','bank','bank','bank'};
Thanks
Jason

Akzeptierte Antwort

Stephen23
Stephen23 am 25 Sep. 2024
Bearbeitet: Stephen23 am 25 Sep. 2024
"How can I retain the decimal numbers "
A = [n,double([MaxI,MinI]),medianMaxIntensity, Hlg,Bren,fwhm2D];
% ^^^^^^^^ ^^
or
A = [n,double(MaxI),double(MinI),medianMaxIntensity, Hlg,Bren,fwhm2D];
% ^^^^^^^ ^ ^^^^^^^ ^
Explanation:
  1 Kommentar
Jason
Jason am 25 Sep. 2024
Thanks, I have just read this - I didnt know about this at all.
https://uk.mathworks.com/help/matlab/matlab_oop/concatenating-objects-of-different-classes.html
MATLAB Concatenation Rules
MATLAB® follows these rules for concatenating objects:
  • MATLAB always attempts to convert all objects to the dominant class.
  • User-defined classes take precedence over built-in classes like double.
  • If there is no defined dominance relationship between any two objects, then the leftmost object dominates (see Class Precedence).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by