How can I join two vectors (integer and decimal)?

I have two vectors for the same number (type double): one is the integer part and the other is the decimal part. Both the same lenght. Can I join them in one vector?
I have A = [1 2 3 4 5]; B = [6 7 8 9 10];
I want a vector C = [1.6 2.7 3.8 4.9 5.10];
Thanks in advance.

5 件のコメント

dpb
dpb 2018 年 11 月 24 日
How would you do it w/ pencil and paper if required to "show your work?"
Can you do that in ML?
Antonio Amor
Antonio Amor 2018 年 11 月 24 日
I suposse that I would divide the decimal vector by 10^n, where n is the lenght of each number. Then, I would add the decimal and the integer vectors. But no, I can't do it in Matlab, it's my first day.
dpb
dpb 2018 年 11 月 24 日
Close but why the n? Your fraction is the tenth's location by the problem description.
What have you tried; have you worked through the "Getting Started" tutorials on Matlab syntax and operators (paying particular attention to array operations)?
Antonio Amor
Antonio Amor 2018 年 11 月 24 日
The n is because not all the numbers of the decimal vector have the same length.
That's what I am going to do: I'm going to read some tutorials. The problem is that the deadline for the work I have to do is next Tuesday and I have no idea!
Thank you so much!
dpb
dpb 2018 年 11 月 24 日
Ah! I didn't notice the actual numbers...good catch! I was going for the specific trivial answer.
Look up "dot" operators by reading section on Array vs. Matrix Operations for how to handle the array "the Matlab way".
How can you compute the magnitude of the values to which need respectifve power of B (a specific transcendental function may come to mind)???

サインインしてコメントする。

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 24 日
編集済み: madhan ravi 2018 年 11 月 24 日

1 投票

One nasty way which is highly discouraged:
>> A = string([1 2 3 4 5]);
B = string([6 7 8 9 10]);
C=strcat(A,'.',B);
C=str2double(C)
C =
1.6000 2.7000 3.8000 4.9000 5.1000
>>

2 件のコメント

Antonio Amor
Antonio Amor 2018 年 11 月 24 日
Nasty or elegant, is suitable and useful.
Thank you!
madhan ravi
madhan ravi 2018 年 11 月 24 日
Anytime :) , MATLAB makes life a lot more easier so take your classes seriously , it will help you in your higher studies, HAPPY MATLAB(ing).

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2018 年 11 月 24 日

2 投票

C=A+B./10.^fix(log10(B)+1);

7 件のコメント

madhan ravi
madhan ravi 2018 年 11 月 24 日
+1 efficient answer
dpb
dpb 2018 年 11 月 24 日
I didn't really want to post the solution but to try to lead OP towards it...but it appeared he bailed out early...
madhan ravi
madhan ravi 2018 年 11 月 24 日
Clearly understood @dpb :)
dpb
dpb 2018 年 11 月 24 日
編集済み: dpb 2018 年 11 月 24 日
As were your self-deprecating comments to your "Answer"... :)
madhan ravi
madhan ravi 2018 年 11 月 24 日
That’s why your referred as a true motivator ❤️
dpb
dpb 2018 年 11 月 26 日
編集済み: dpb 2018 年 11 月 26 日
Awwww...blushes... :)
madhan ravi
madhan ravi 2018 年 11 月 26 日
:)

サインインしてコメントする。

カテゴリ

製品

リリース

R2018b

質問済み:

2018 年 11 月 24 日

コメント済み:

2018 年 11 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by