James Baker - MATLAB Cody - MATLAB Central

James Baker

31818
Rank
3
Badges
138
Score
1 – 18 of 18

James Baker submitted a Comment to Problem 1024. Doubling elements in a vector

B = [ A A]; Is a valid answer! Your problem statement says nothing about the element in vector b being in order. Test 2 is correct for only one case.

on 8 Jan 2024

James Baker received Solver badge for Solution 13003321

on 8 Jan 2024

James Baker received Commenter badge for Problem 55. Counting Sequence

on 7 Jan 2024

James Baker submitted a Comment to Problem 55. Counting Sequence

I’m pretty new to programming and took on the cody counting sequence problem. My sample code is below. I wasn’t going for the most compact code and wanted the code to be generic to solve any size input vector X. My code does work, but when I submit it in the problem section, I get an error running the test scripts? Not a wrong result, just errors. Comments - suggestions? Yes, I know the codes messy. lol. x =[ 5, 5, 2, 1,1, 1,1,3]; n = numel(x); seqy = zeros(2*n,1); seqpos=1; seqcount=1; i=1; while i < n ; if x(i) == x( i+1); seqcount = seqcount+1; else seqy(seqpos)=seqcount; seqpos = seqpos+1 ; seqy(seqpos) = x(i); seqpos = seqpos+1; seqcount =1; end i = i+1; end seqy(seqpos) = seqcount; seqy(seqpos+1)=x(i); seqy; c =numel(seqy); h = 1; p =0; while h < c ; if seqy(h) ~= 0; else p=h; b =trimdata(seqy,p-1); break end h= h+1; end y = b; y % final result

on 7 Jan 2024

James Baker received Promoter badge for Problem 55. Counting Sequence

on 7 Jan 2024

1 – 18 of 18
Go to top of page