Hi guys,
I am trying to assignment a character to variable but I guess the variables values defined to only integers or variable so;
if ı write a =k;
matlab will recognize that a variable equal k variable or value but ı want to write that a variable equal 'k' character only . I need a funtion that can recognize 'k' character;
sentence = [ {h} {e} {l}........ {o} {r} {l} {d}];
for n=1:strlenght(sentence)
for an=1:4
j=charsentence(n); %% this line has to configure ı guess
shortset =[shortset j];
end
end
and also guys ,this is inpedendent question, i need a function that can indicate character or other one ı will use in the if condition if j character use or it is not pass.
thank you.

4 Kommentare

dpb
dpb am 12 Apr. 2020
Explain what you're actually trying to accomplish -- trying to debug uncommented code is tough without knowing what the end objective is particularly.
For example, what is num2cell there for? The user was asked to enter a sentence; why would one expect a general sentence to have a number in it? Is there some other instruction we don't know about?
Ugur Sahin
Ugur Sahin am 12 Apr. 2020
okkay I will edit.
dpb
dpb am 13 Apr. 2020
Bearbeitet: dpb am 13 Apr. 2020
Well, if somebody is going to enter a sentence, then you'll receive something like
sentence='hello world!';
which is a char() string variable.
You address each character in it as in any other array:
>> sentence='hello world!';
>> sentence(1)
ans =
'h'
>> sentence(end-3:end)
ans =
'rld!'
>>
After that, I still don't follow what you're trying to do next...
Give us the input and then an expected output.
Ugur Sahin
Ugur Sahin am 13 Apr. 2020
thank you this is useful.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 13 Apr. 2020

0 Stimmen

To get the character k in variable a, you don't need a function, you simply need to add quotes around it:
a = 'k';
That's way easier than having a function.
There is also an ischar() function that you might want to know about, as well as isnumeric() and others.

2 Kommentare

Anicyah
Anicyah am 3 Okt. 2023
what if I can't hardcode tho?
Walter Roberson
Walter Roberson am 3 Okt. 2023
What would the input be in that situation?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by