Hello. I have a really specific question. In running the code in the description, Matlab echoes all the values I need (10 numbers), but only considers the last value from10 (so it plots only the last value). How can I make it consider all the values?
1 次查看(过去 30 天)
显示 更早的评论
I am running a code that reads a binary file (where I have my data, which is a big 120x500 matrix) for each time step (I chose 10 as the number of steps, for simplicity). Therefore, I have 3 matrices, each 120x500 in size. I did the mean of every matrix, obtaining a 1x500 row vector for each matrix, and the mean of each row vector. In the end, I obtained 10 number values. The problem is that I can see all the 10 number values echoed on the command window, but Matlab only considers 1 value, namely the 10th value. So, when I try to plot this, it only plots the last value, but I want to plot the whole row of 10 numbers.
The code goes like this:
function TMP=open83B_edited(filename)
fid = fopen('/Documents/SONAR/LB3/25oct2013-072004.83B');
%read file header
for i = 1:10
TMP.fileheader.ASCII8 = fread(fid,[1 1], 'uint8=>char');
TMP.fileheader.ASCII8;
TMP.fileheader.ASCII3 = fread(fid,[1 1], 'uint8=>char');
TMP.fileheader.ASCII3;
TMP.fileheader.ASCII7 = fread(fid,[1 1], 'uint8=>char');
TMP.fileheader.ASCII7;
TMP.fileheader.Version = fread(fid,[1 1], 'uint8=>char');
TMP.fileheader.TotalBytes = fread(fid,[1 1], 'ubit24',0, 'ieee-be');
TMP.fileheader.Reserved1 = fread(fid,[1 1], 'uint8=>char');
TMP.fileheader.DateTime = fread(fid,[1 25], 'uint8=>char');
TMP.fileheader.DateTime;
TMP.fileheader.GPSShipsPositionLatitude = fread(fid,[1 14], 'uint8=>char',0, 'ieee-be');
TMP.fileheader.GPSShipsPositionLongitude = fread(fid,[1 14], 'uint8=>char',0, 'ieee-be');
TMP.fileheader.GPSShipsSpeed = fread(fid, 1, 'uint8',0, 'ieee-be');
TMP.fileheader.Heading = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.PitchAngle = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.RollAngle = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.HeadingAngle = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.Beams = fread(fid, [1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.SamplePerBeam = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.SectorSize = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.StartAngle = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.AngleIncrement = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.AcousticRange = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.AcousticFrequency = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.SoundVelocity = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.RangeResolution = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.PulseLength = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.ProfileTiltAngle = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.RepetitionRate = fread(fid,[1 1], 'uint16',0, 'ieee-be');
TMP.fileheader.PingNumber = fread(fid, 1, 'uint32',0, 'ieee-be');
TMP.fileheader.Reserved2 = fread(fid,[1 1], 'ubit24',0, 'ieee-be');
TMP.fileheader.SonarXOffset = fread(fid,[1 1], 'uint32',0, 'ieee-be');
TMP.fileheader.SonarYOffset = fread(fid,[1 1], 'uint32',0, 'ieee-be');
TMP.fileheader.SonarZOffset = fread(fid,[1 1], 'uint32',0, 'ieee-be');
TMP.fileheader.Reserved3 = fread(fid,[1 143], 'uint8',0, 'ieee-be');
%Start of beam output bytes (500 range bins per beam) intensity values
TMP.SonarReturnData.BeamsOutput = fread(fid,[120 500], 'uint8',0, 'ieee-be');
TMP.SonarReturnData.BeamsOutput;
TMP.AveragedOutput = mean(mean(TMP.SonarReturnData.BeamsOutput))
end
fclose(fid);
An the output of the running code goes like this:
>> TMP=open83B_edited_2('25oct2013-072004.837')
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 0
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 0.4777
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 0.9750
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 1.4959
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.0763
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.6397
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.7426
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.7948
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.8090
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.7661
TMP =
fileheader: [1x1 struct]
SonarReturnData: [1x1 struct]
AveragedOutput: 2.7661
So it can be seen that it only considers the last number, namely 2.7661, although it echoes all of them. I want to be able to plot the above numbers, not only the last one. Sorry for the long message. Thank you!
Adrian
0 个评论
回答(1 个)
A Jenkins
2014-4-3
You need to store all 10 in either a structure of arrays or an array of stuctures , instead of overwriting it each time. You can use your loop index.
So something like
TMP(i).fileheader.ASCII8
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!