The Output structure of a code is showing different outputs in command window and workspace
Afficher commentaires plus anciens
When working on a program, after executing it and checking output in MATLAB command window and in output from workspace is giving different outputs. Which is correct output here and what is this happening?
Command window output:

11 commentaires
John D'Errico
le 13 Juil 2024
Modifié(e) : John D'Errico
le 13 Juil 2024
Why do you think it is different? In fact, they look the same to me. They are both as correct as the other, and the same.
Check each field. Those I could check all seem to be identical. Look carefully at what pcapReader shows.
Manikanta Aditya
le 13 Juil 2024
@Manikanta Aditya, the other variables are from the structs that are being expanded in the viewer but only the top level fieldnames are displayed at the command line.
I never use the workspace viewer so I'm not at all familiar with its interface, but if I open it locally and then select a table variable, say, then I see only that table in the new tab of the variable name. Looks to me as though that's what the OP has done here.
But, without the original object we can't exactly duplicate the display because the content will be dependent upon what was read...
ADDENDUM
I did have a struct after all; it does the same thing in showing the fields in the struct only, not other variables in command scope. They're expanded to their underlying type -- how far depends on type and size; a ch() string appears to be displayed, a cellstr shows up as just a cell variable; have to open it to see the content itself...
dpb
le 13 Juil 2024
@Manikanta Aditya: Save the object to a .mat file and attach here with the paperclip icon; nothing more anybody can do with the image but look at it...
John D'Errico
le 13 Juil 2024
Remember, just because two different views of something do not appear identical at a glance, you cannot assume they are not so. To the extent I was able to see, the fields all seem to contain the same information, though they were shown in different order. That order is not relevant.
If you want someone to check that more carefully, you would need to post the object itself, since all we were shown is a picture of some text.
Manikanta Aditya
le 14 Juil 2024
Download <hexdump> from the File Exchange and run it on the input file header -- the first 64 bytes will be enough. Save the output to a text file and attach it. We'll at least be able to see the header info without any risk of sharing sensitive data, although it would seem highly unlikely there's anything that would be given away just from the header object that could be too incriminating...
>> hexdump('..\..\..\Downloads\Sample.pcapng',32)
0a 0d 0d 0a 90 00 00 00 4d 3c 2b 1a 01 00 00 00 *.......M<+.....*
ff ff ff ff ff ff ff ff 03 00 38 00 36 34 2d 62 *ÿÿÿÿÿÿÿÿ..8.64-b*
>>
that does show the 0A0D0D0A bytes. Be useful to see what yours shows...but it's hard to imagine the extra fields aren't there if the struct output shows they are...
Manikanta Aditya
le 14 Juil 2024
dpb
le 14 Juil 2024
As Walter noted, have you compared
obj
disp(obj)
struct(obj)
?
Manikanta Aditya
le 15 Juil 2024
Manikanta Aditya
le 16 Juil 2024
Réponse acceptée
Plus de réponses (1)
dpb
le 13 Juil 2024
0 votes
As @John D'Errico says, they're both correct only the workspace browser has unfolded the various struct content that is only displayed as the struct, not the content of the struct in command window. So, there's more to the struct than is just displayed at the command window, but it would be very annoying if the command window expanded everything...
4 commentaires
Manikanta Aditya
le 13 Juil 2024
We cannot do anything but look at the image you posted; the workspace viewer expanded what is in the returned object. All we can do is say those are there if the browser says they are.
What is returned will be totally dependent upon what the content of what was read is and how it was read -- if the reader is returning ng data, it must be in the file regardless the extension that was used for the file.
There are "magic" bytes used at the beginning of the file to allow the reader code to determine whether a file is a pcap or a pcapng file. The difference between the two is the pcap file has only a single 4-byte code while a ng version has a different initial 4-byte code plus a 4-byte length followed by a second 4-byte code.
Specifically, the values are
pcap: D4C3B2A1 or A1B2C3D4 (depends on byte order)
pcapng: 0A0D0D0A + (4 bytes length) + 4D3C2B1A or 1A2B3C4D (depends on byte order)
So, the reader first scans the file header content to distinguish and then adapts to what the content of the file shows, not presuming from the extension of the file name.
NOTA BENE: If the reader were to use the file extension only, then the read operation would fail because the actual file format would not match that expected given the differences between the two types.
Again, attach the file and the reader object and your (minimal) code...images aren't of any use.
Manikanta Aditya
le 13 Juil 2024
Manikanta Aditya
le 13 Juil 2024
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!