Removing single quotations from a character array

조회 수: 13 (최근 30일)
Frederick Koth
Frederick Koth 2019년 11월 18일
댓글: Walter Roberson 2022년 7월 28일
So I have this code:
function [myRes] = getAsDMS(angle)
angle = 20.5;
d = floor(angle);
m = floor((angle - d) * 60);
s = round(((angle-d)* 60 - m)*60);
str = [num2str(d), '°' , num2str(m),'''', num2str(s), '"'];
myRes = str;
end
Which gives the result:
'20°30'0"'
But I need my answer to not include the single quotation marks that enclose the answer.

답변 (1개)

James Tursa
James Tursa 2019년 11월 18일
Your answer does not include the bounding single quotation marks ... that is just a display artifact for how MATLAB prints character strings to the screen. The myRes variable only includes the characters between the bounding single quotation marks.
  댓글 수: 3
Garvit Amipara
Garvit Amipara 2022년 7월 27일
편집: Garvit Amipara 2022년 7월 27일
Hello there,
(Matlab2021b)
there was no help related to removing quotes from display command with variable names. I hope this is a right place to ask. Please help.
This is the part of the code that should display variables- Running Drivecycle: UDDS
I have tried string and convertStringsToChars (%2 in code) as well, both returns answers with quotes and brackets.
get_cycle_name={'UDDS' 'HWFET' };
for DS = 1:2
cycle_name = get_cycle_name(DS); %1
cycle_name1 = convertStringsToChars(cycle_name); %2
disp(['Running Drivecycle:', cycle_name ]); %1
disp(['Running Drivecycle:', cycle_name1 ]); % 2
end
this displays,
{'Running Drivecycle:'} {'UDDS'} %1
{'Running Drivecycle:'} {'UDDS'} %2
Desired output: Running Drivecycle: UDDS
Walter Roberson
Walter Roberson 2022년 7월 28일
cycle_name = get_cycle_name{DS} ; %1

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

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by