MATLAB: How do i create new variable from 31 variables with one column create variables dynamically i have 31 variables with 1 column each variable and i want to create new variable from 31 variables with one column Best Answer vertcat(v1, v2, v3, v4, ...., v31)orhorzcat(v1, v2, v3, v4, ...., v31)The first of these would give you one single column of output, and the second of those would give you 31 columns.The syntax [v1; v2; v3; ...; v31] is the same as vertcat(), and the syntax [v1, v2, v3, ..., v31] is the same as horzcat() Related SolutionsMATLAB: How to define an arbitrary constant for equations If you are talking about making an assumption, you can do it as follows:v1=6;v3=18;syms v2 v4 v5 v6eqn1= -v4+v5==-v3;eqn2= -v2+v6==v3;eqn3= -v5-v6==-v1;assume(v6~=0)[v2 v4 v5 v6]=solve(eqn1, eqn2, eqn3);[v2 v4 v5 v6] MATLAB: Variable variant use cell arrayX=rand(20,1)Y=rand(20,1)p = mat2cell([X Y],ones(20,1),2)bad versionfor j1 = 1:size(X,1) jc = num2str(j1); eval(['p' jc '= [X(' jc '), Y(' jc ')]']);endSo do not ever! Use the better 'p{1}' of the first variant instead of 'p1' Related QuestionVariable definitionGeneric index select, without loopsUsing VariablesHow to explicitly change the colors of the bars in a stacked bar graphSliced variables
Best Answer