필터 지우기
필터 지우기

Populating values across a cell

조회 수: 1 (최근 30일)
Hari krishnan
Hari krishnan 2018년 9월 5일
댓글: Hari krishnan 2018년 9월 8일
My data is composed of four cells coming from 4 text files(length of num_files is 4 ). Within each cell values are stored in strings. I wanted to perform an operation in each cell of the data. Once the operation is completed, the data is saved to a cell data_pro .Unfortunately, in data_pro the values in the first cell is duplicated again in the rest of the cells. Any help to solve this will be appreciated.
num_files = length(filenames);
data_pro = cell(1);
for pp = 1:num_files
data_ts = data{pp}(:,1);
new_frame = contains(data_ts,'-');
frame_num = cumsum(newframe);
data_with_frames = [num2cell(frame_num) data{pp}];
data_pro{pp} = data_with_frames;
end

채택된 답변

James Tursa
James Tursa 2018년 9월 5일
편집: James Tursa 2018년 9월 5일
There is nothing in your loop body that uses the index pp other than the data_pro{pp} assignment, so every data_pro{pp} is going to get the same assignment. Maybe you need to use something like data{pp} instead of data{1,1} in your loop body.
  댓글 수: 3
James Tursa
James Tursa 2018년 9월 6일
Step through with the debugger to see what is going on. Open up the code in the editor and click just to the left of a line number to set a break point, then run your code. When it pauses at the line, you can examine variables etc and step through your code one line at a time.
Hari krishnan
Hari krishnan 2018년 9월 8일
@Hi James, I found the answer. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by