Hi,
I've got 4 values: D=1 E=3 F=2 G=9
and I want to combine them to 1 value: Total=DEFG (in this example: 1329)
Anyone an idea how I could fix this?

 채택된 답변

the cyclist
the cyclist 2011년 10월 16일

0 개 추천

Here's one way:
D=1;
E=3;
F=2;
G=9;
x = str2num([num2str(D),num2str(E),num2str(F),num2str(G)])
There are probably more efficient ways, but I am feeling lazy. Note that upstream from where you define these variables like this, there were probably MUCH better naming conventions or other methods that would have made this much cleaner.

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 10월 16일
x = str2double(sprintf('%d%d%d%d', D, E, F, G));

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Wayne King
Wayne King 2011년 10월 16일

0 개 추천

H = cat(1,D,E,F,G);
Roberto
Roberto 2011년 10월 16일

0 개 추천

That doesn't work like I wanted... I need a variable with the answer which is 1329.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2011년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by