필터 지우기
필터 지우기

How to create a structure array with intial values as zeros?

조회 수: 10 (최근 30일)
Matt Learner
Matt Learner 2012년 2월 13일
답변: Ehsan 2014년 6월 25일
I want to create a structure array with initial values as zeros. Say for example I have an array of structure called "struc". and it has 2 fields with 2 D array "max(5,6)" and "min(5,6)". How to allocate memory space for this.i.e., how to allocate zeros for this structure and field. I tried "struct(2).max(5,6)=zeros", "struct(2).min(5,6)=zeros" but the zeros are allocating only to the second structure i.e. stuc(2) but not to struct(1). I need zeros for both. Kindly help me

답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 2월 13일
So something like:
struct('name1',{zeros(5,6);zeros(5,6)},'name2',{[];magic(4)})
perhaps?

Ehsan
Ehsan 2014년 6월 25일
You might want to use a "for" loop for the first element of your structure. Then, assign a zeros(5,6) to each array. I guess this could be an automatic way of allocating zeros to a structure.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by