user interface - Accessing a matrix in Matlab -


assume user input data below. define matrix cost. matrix created 3 3 matrix. matrix should form this:

cost = [c11 c12 c13                       c21 c22 c23           c31 c32 c33] 

since want display set of row, :

c1 = cost(1,:); % become c1 = c11 c12 c13  c2 = cost(2,:); % become c2 = c21 c22 c23  c3 = cost(3,:); % become c3 = c31 c32 c33 

then want value in matrix. this.

c11 = cost(1,1);  c12 = cost(1,2);  c13 = cost(1,3);  c21 = cost(2,1);  c22 = cost(2,2);  c23 = cost(2,3);  c31 = cost(3,1);  c32 = cost(3,2);  c33 = cost(3,3); 

so equation want use type of matrix.

lambda =  ((8*c13*c23*c33*pdt)+(4*c12*c23*c33)+(4*c13*c22*c33)+(4*c13*c23*c32)) ./ (4*c23*c33)+(4*c13*c33)+(4*c13*c23)); 

so problem is, if want make 4 3 matrix, , generate matrix this:

cost = [c11 c12 c13                       c21 c22 c23           c31 c32 c33           c41 c42 c43] 

the equation want use matrix(4 3) quite different. how im gonna it? need use if else statement? or while? can me solve this? can create code?

why explicitly create variables c11, c12, ...? surely easier access matrix in equation this:

lambda = ((8*cost(1,3)*cost(2,3)*cost(3,3)*pdt)+(4*cost(1,2)*cost(2,3)*cost(3,3)+(4*cost(1,3)*cost(2,2)*c(3,3))+(4*cost(1,3)*cost(2,3)*cost(3,2)) ./ (4*cost(2,3)*cost(3,3))+(4*cost(1,3)*cost(3,3))+(4*cost(1,3)*cost(2,3)));

for question, yes, use simple if statment, this:

if size(cost,1) == 3

  %equation matrix size 3x3 

else

  %equation matriz size 4x3 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -