How can i access the values in a cell array and assign multiple values from column of the cell to a variable using a for loop?

조회 수: 4 (최근 30일)
Hi. I have a cell 30x1 and each cell has 4 columns and 1 row. I want to assign the row values from 4 columns to 4 variables using a for loop. I tried using
for i = range(1:30)
for j = range(1:4)
Y = P{i,1}(1,j);
A = P{i,1}(1,2);
B = P{i,1}(1,3);
C = P{i,1}(1,4);
end
end
but I only assigned the last value form the last cell to the variable. Can someone help me where am i making an error?

답변 (1개)

Image Analyst
Image Analyst 2018년 10월 10일
Y, A, B, and C get overwritten on every single iteration.
Why not simply use cell2mat(P)?
  댓글 수: 2
Harsh Patel
Harsh Patel 2018년 10월 10일
so i should use the for loop after the applying cell2mat to the cell? Because i need to assign values from all rows and each column to single variable.
Image Analyst
Image Analyst 2018년 10월 10일
How are you combining a bunch of numbers into a single number? Summing them? Taking their mean? Please give a small example.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by