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.
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.
Thank you for the help
y = [x(1),x(end)];
#strcat(x(1),x(length(x)));
very easy like it!
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"
Nice!
Only need:
out = x([1 end])
This is legal even if length(x) == 1, because in that case, x(1) == x(end)
that is it
3083 Solvers
4602 Solvers
Given an unsigned integer x, find the largest y by rearranging the bits in x
783 Solvers
How many trades represent all the profit?
520 Solvers
Given a square and a circle, please decide whether the square covers more area.
351 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!