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
266 Solvers
446 Solvers
527 Solvers
Find the dimensions of a matrix
383 Solvers
String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values
414 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!