How to combine multiple numbers into 1 number?
3 views (last 30 days)
Show older comments
I have the numbers R1, R2, Zr1, that I want to fuse together into 24000 . Zr1 is an array, while R1 and R2 are double. I have tried strcat but it only produces 240 0 0 which is not the intended 24000
R1 = 2
R2 = 4
Zr1 = 0 0 0
1 Comment
Stephen23
on 25 Feb 2023
"Zr1 is an array, while R1 and R2 are double"
All doubles are arrays. Scalars are not a separate type, because in MATLAB everything is an array:
Accepted Answer
Stephen23
on 25 Feb 2023
Edited: Stephen23
on 25 Feb 2023
General solution:
R1 = 2;
R2 = 4;
Zr1 = [0,0,0];
V = [R1,R2,Zr1];
N = 10.^(numel(V)-1:-1:0) * V(:)
4 Comments
Steven Lord
on 25 Feb 2023
Another way to generate the Q vector is with logspace.
Q = logspace(4, 0, 5)
More Answers (1)
Alan Stevens
on 25 Feb 2023
Edited: Alan Stevens
on 25 Feb 2023
Do you mean
R1 = 2; R2 = 4; Zr1 = [0 0 0];
R = R1*10^4+R2*10^3+Zr1(1)*10^2+Zr1(2)*10+Zr1(3)
Alternatively:
R1 = 2; R2 = 4; Zr1 = [0 0 0];
R = [R1, R2, Zr1]
M = 10.^[4 3 2 1 0]
R = M*R'
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!