问题41.细胞木匠
解决方案统计
Problem Comments
-
11条评论
There has been a function added in 2013a for this!!
I make it in R2013a,but I don't know the R2012b or other previous versions have this function.
Most of the solutions consider that delim=1char
i don't know
棘手的一个!
不错
Hello everyone :)
Just a quick one: the code I provide below here work fine in Matlab (r2019b), so each solution matches the one I'm asked to provide. However, when evaluating the code on Cody, I get "Assertion failed".
Can anyone please explain me if it's a matter of conversion or some details I am missing?
KR,Andrea
out_str=[];
for jj=1:length(in_cell)
tmp=char(in_cell(jj));
C = [TMP,DELIM];
if jj==1
out_str = c;
else
out_str=[out_str,c];
end
end
I used strjoin(in_string,' ')
passed the first two, third one failed.
no way for me
nice biology concept
This one is kinda hilarious, as (hint here) it may punish you for defining TOO much...
解决方案评论
-
1条评论
join doesn't work here?
-
1条评论
超级简单
-
1条评论
thanks!
-
1条评论
这将是单个内置功能的复制。
-
1条评论
有趣的!
-
2条评论
Assertion fails in Cody even though the assertion passes in MATLAB R2014b. Does any one know why?
Hi. The assertion could only have passed outside of Cody if the wrong "correct solution" were specified for comparison, and this would happen if you copy the HTML-rendered text — due to a kind of bug in the way the solution vector is displayed on the Cody webpage (better: copy from the HTML _source code_). -----
The correct solution has delimiters (here shown as ^ for clarity) as in 'this^one^^has^ ^some tricky^stuff', whereas your code produces 'this^one^has^some tricky^stuff', so you don't get the correct result between "one" and "has", nor between "has" and "some".
-
3条评论
我认为必须检查测试2。
I compared the test 2 correct answer with the program output using strcmp, and it gave 1 as output.( This was before introducing the program lines which also take into consideration the single space given in 5th element of in_cell in test 2)
任何已经解决或有想法解决的人,请让我知道我程序中的错误是什么。
顺便说一句,谢谢,程序可能有点冗长。
THE TEST CASE 2 OUTPUT YOU HAVE DISPLAYED IS WRONG
更正它。
这里有两个问题:
(1) The HTML display in Cody automatically only displays a single space. Therefore, while the solution *vector* _specified_ as the answer to Test 2 in Cody is correct, the *text* that is _displayed_ is not. You can confirm that the correct information was specified by viewing the HTML source. It is unfortunate that this is not displayed correctly. Of course, any results should match the solution, not the incorrect display.
(2) Your candidate solution fails because it is incorrect. Even if it matches the HTML-parsed display, it doesn't match the true specified solution vector. To make this apparent, imagine if delim='^' (no other changes). The correct solution to Test 2 would then be 'this^one^^has^ ^some tricky^stuff', whereas your output would be 'this^one^has^ ^some tricky^stuff' (provided in Solution 1280078). In other words, you needed a double space between "one" and "has".
-
1条评论
My solution is:
函数out_str = celltr_joiner(in_cell,delim)
y=in_cell;
y(find(cellfun(@isempty,cellfun(@strtrim,y,'UniformOutput',false))))=[];
out_str = strjoin(y);
out_str(find(out_str==' '))=delim;
end
在MATLAB上,所有测试通过,但在Cody网站上第二个测试失败!
-
2条评论
This code is working as expected in MATLAB command window. can i know why it is failed here
why deblank?
-
2条评论
-
1条评论
I think there is something wrong here, this solution seems to work.
-
2条评论
很好,我从未听说过这个!
I had tried this, but kept getting: "strjoin not found" on my workstation :(
So I had to work around it.
-
1条评论
最好的!(没有Str Join)
-
2条评论
answers just the test suite...
有更好的作弊方法!
-
1条评论
Simple and easy to understand, and works in versions before strjoin appeared.
-
1条评论
gh,循环!
-
1条评论
printf works wonders