How do structures work?

조회 수: 7 (최근 30일)
Eric
Eric 2024년 4월 30일
편집: Voss 2024년 4월 30일
How do structures work? I've been trying a smoewhat big struct file but the workspace cannot seem to be able to find the values of the structure (the values of the fields are missing). Here is the code. Please help me I do not know what to do.
Default_GP = struct ( ...%
...% -- Connection Properties --
...%
'Platform', "B200", ...
'SerialNum', "321E19C", ...
...%
...% -- Configuration Propreties --
...%
...% Frequency
...%
'CenterFrequency', 101e6, ...
'FrequencyCorrection', 0, ... //LO offset
'FrequencyStepsString' ,{{'1 Hz','10 Hz','100 Hz','1 kHz','10 kHz','100 kHz','1 MHz','10 MHz','100 MHz'}}, ...
'AllFrequencySteps',[1,10,100,1e3,10e3,100e3,1e6,10e6,100e6],...
'FrequencyStep',100e3,...
...%
...% Reciever Gain
...%
'RecieverGain', 0,... % 76 dB - max reciver gain
...
...
'AllPPSSources', {{"Internal", "External", "GPSDO"}},...
'PPSSource', "Internal",...
'AllClockSources', {{"Internal", "External", "GPSDO"}},...
'ClockSource', "Internal",...
...%
...% Output
...%
'AllSampleRates', {},... % range of sample rates 5MHz - 61.44MHz
'SampleRateSteps', {{'0.1 MHz', '1 MHz','10 MHz'}},...
'AllSampleRateSteps', [0.1e6, 1e6, 10e6],...
'SampleRate', 32e6,... % Master Clock Rate
...
'TransportDataTypeStrings', {{"int16", "int8"}},...
'TransportDataType', "int16",...
'OutputDataTypeString', {{"int16", "int18", "single", "double"}},...
'OutputDataType', "double",...
...
'AllSamplesPerFrameString',{{'4096','8192','16384','32768','65536','131072','262144'}},...
'AllSamplesPerFrame',[4096,8192,16384,32768,65536,131072,262144],...
'SamplesPerFrame',131072,...
...
'EnableBurstMode',false,... % Ensure a set of frames without overrun of USRP B200 output
'NumFramesInBurst',10,... % Number of frames in contiguous burstof USRP B200 output
...%
...% Baseband Decimation
...%
'AllDecimationFactorsRanges', {{'[1, 128]', '[128, 256]', '[256-512]'}},...
'DecimationMultiplesOf', [1, 2, 4],...
'DecimationFactor', 1); % to be added
  댓글 수: 1
Stephen23
Stephen23 2024년 4월 30일
편집: Stephen23 2024년 4월 30일
"the values of the fields are missing"
Because your entire structure is empty it cannot contain any data:
"Please help me I do not know what to do"
You probably want a scalar structure. In that case note very carefully what the documentation explains about cell arrays which are input to the STRUCT command. If you want a field to contain an empty cell array, then you will need to nest it inside a scalar cell array:
S = struct('x',{{}},'y',pi)
S = struct with fields:
x: {} y: 3.1416

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

답변 (1개)

Voss
Voss 2024년 4월 30일
편집: Voss 2024년 4월 30일
To create a scalar (as opposed to a 0x0) structure array, this
'AllSampleRates', {},...
needs to be
'AllSampleRates', {{}},...
Explanation: struct creates a structure array, the size of which is determined by the value arguments. In particular (from the documentation):
  • If value is an empty cell array {}, then s is an empty (0-by-0) structure.
  • If value is a nonscalar cell array, then s is a structure array with the same dimensions as value.
  • If value is not a cell array, or if value is a scalar cell array, then s is a scalar structure.
Interestingly, all the other cell array value arguments in your code are already scalars; you only missed making the 0-by-0 cell array {} into the scalar cell array {{}} for AllSampleRates.
Default_GP = struct ( ...%
...% -- Connection Properties --
...%
'Platform', "B200", ...
'SerialNum', "321E19C", ...
...%
...% -- Configuration Propreties --
...%
...% Frequency
...%
'CenterFrequency', 101e6, ...
'FrequencyCorrection', 0, ... //LO offset
'FrequencyStepsString' ,{{'1 Hz','10 Hz','100 Hz','1 kHz','10 kHz','100 kHz','1 MHz','10 MHz','100 MHz'}}, ...
'AllFrequencySteps',[1,10,100,1e3,10e3,100e3,1e6,10e6,100e6],...
'FrequencyStep',100e3,...
...%
...% Reciever Gain
...%
'RecieverGain', 0,... % 76 dB - max reciver gain
...
...
'AllPPSSources', {{"Internal", "External", "GPSDO"}},...
'PPSSource', "Internal",...
'AllClockSources', {{"Internal", "External", "GPSDO"}},...
'ClockSource', "Internal",...
...%
...% Output
...%
'AllSampleRates', {{}},... % range of sample rates 5MHz - 61.44MHz
'SampleRateSteps', {{'0.1 MHz', '1 MHz','10 MHz'}},...
'AllSampleRateSteps', [0.1e6, 1e6, 10e6],...
'SampleRate', 32e6,... % Master Clock Rate
...
'TransportDataTypeStrings', {{"int16", "int8"}},...
'TransportDataType', "int16",...
'OutputDataTypeString', {{"int16", "int18", "single", "double"}},...
'OutputDataType', "double",...
...
'AllSamplesPerFrameString',{{'4096','8192','16384','32768','65536','131072','262144'}},...
'AllSamplesPerFrame',[4096,8192,16384,32768,65536,131072,262144],...
'SamplesPerFrame',131072,...
...
'EnableBurstMode',false,... % Ensure a set of frames without overrun of USRP B200 output
'NumFramesInBurst',10,... % Number of frames in contiguous burstof USRP B200 output
...%
...% Baseband Decimation
...%
'AllDecimationFactorsRanges', {{'[1, 128]', '[128, 256]', '[256-512]'}},...
'DecimationMultiplesOf', [1, 2, 4],...
'DecimationFactor', 1); % to be added
Default_GP
Default_GP = struct with fields:
Platform: "B200" SerialNum: "321E19C" CenterFrequency: 101000000 FrequencyCorrection: 0 FrequencyStepsString: {'1 Hz' '10 Hz' '100 Hz' '1 kHz' '10 kHz' '100 kHz' '1 MHz' '10 MHz' '100 MHz'} AllFrequencySteps: [1 10 100 1000 10000 100000 1000000 10000000 100000000] FrequencyStep: 100000 RecieverGain: 0 AllPPSSources: {["Internal"] ["External"] ["GPSDO"]} PPSSource: ["Internal"] AllClockSources: {["Internal"] ["External"] ["GPSDO"]} ClockSource: ["Internal"] AllSampleRates: {} SampleRateSteps: {'0.1 MHz' '1 MHz' '10 MHz'} AllSampleRateSteps: [100000 1000000 10000000] SampleRate: [32000000] TransportDataTypeStrings: {["int16"] ["int8"]} TransportDataType: ["int16"] OutputDataTypeString: {["int16"] ["int18"] ["single"] ["double"]} OutputDataType: ["double"] AllSamplesPerFrameString: {'4096' '8192' '16384' '32768' '65536' '131072' '262144'} AllSamplesPerFrame: [4096 8192 16384 32768 65536 131072 262144] SamplesPerFrame: [131072] EnableBurstMode: [0] NumFramesInBurst: [10] AllDecimationFactorsRanges: {'[1, 128]' '[128, 256]' '[256-512]'} DecimationMultiplesOf: [1 2 4] DecimationFactor: [1]

Community Treasure Hunt

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

Start Hunting!

Translated by