MATLAB: How to write case in simple way MATLABsimulink Hi, Is there a simple/short way to write switch case ? instead : case {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} … … otherwise … something like case 1 to 20 or case {1:20} ? Thanks, Henry Best Answer One way>> cssm(12) 12wherefunction cssm(jj) switch jj case num2cell([1:24]) disp( jj ) otherwise disp('failed') endendAndcase num2cell([1:24])may be replaced bycase num2cell(1:24)in contemporary releases of Matlab Related SolutionsMATLAB: Error: Unable to perform assignment because the left and right sides have a different number of elements. You are using a double for loop. I advise its best to use something like thisfor ii=1:24 for jj=1:24 z(ii,jj)=normrnd(mu_SC(ii),std_SC(jj),1000); endend MATLAB: Error Deleting column from cell r = cell(size(r))for jj = 1:numel(r) r{jj} = gene{jj}(:, [1,2,4]);endWith an explicite indices it would be: r{jj}(:, 1:3) = gene{jj}(:, [1,2,4]);But this is not required, because this is the default already. Related QuestionMake cell and put number on itQuestion regarding a switch statementI worked on nested loop.How to convert from cell array to multidimensional array
Best Answer