Problem 649. Return the first and last characters of a character array
Solution Stats
Problem Comments
-
4 Comments
There is a difference between string and char array since R2016b. Before that they could be used interchangeably, but now that is no longer true (although I believe some doc pages are still not careful about this).
The title and description have been updated, along with a few new test cases.
Wow this actually is such a great question
good problem
Solution Comments
-
2 Comments
nice!
ELEGANGT!
-
2 Comments
nice simple problem
good problem
-
2 Comments
Why this solution isn't correct? I tried this code on Matlab for pc and it's run correctly, but here on Matlab Cody's platform, it doesn't run. Someone can help me? Thanks
Look at the errors—your function never defines the output variable y.
-
1 Comment
Thank you for the help
-
1 Comment
We can simply use 'append'
function y = stringfirstandlast(x)
y = append(x(1),x(length(x)))
end
-
1 Comment
#strcat(x(1),x(length(x)));
very easy like it!
-
2 Comments
Well, I guess my understanding that string is defined using (" " , i.e. double quotations) is incorrect. I thought class string was formally distinguished from char (defined using ' ', i.e. single quotes). I should have looked at the test-suite.
Yes, the title should be "Return the first and last character of a char array"
-
1 Comment
Nice!
-
1 Comment
that is it
Problem Recent Solvers7376
Suggested Problems
-
1870 Solvers
-
given 3 sides, find area of this triangle
775 Solvers
-
1220 Solvers
-
991 Solvers
-
Find the maximum number of decimal places in a set of numbers
2010 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!