display mat file in matlab - file

I want to display mat file's content to see all the results. I know that I can load it and then double click on it the content are display in the workspace, this case happen when the mat file content few information but when I have mat file content information for more than 13000 record I can't display it. could please any one help me to find any way to display mat file as table?
thanks

I do not know the format of your data (multi-dimensional, structs, cell-arrays), but there is a function called "openvar" which can be very useful for these things.
Let's define a large random 500x500x10 3d-matrix:
large = rand(500,500,10);
This variable contains 2.5 million double-values and takes up close to 20MB of memory. Opening this in the variable editor by double click in the Workspace window on "large" will usually (atleast on my system) give the following message:
"Cannot display summaries of variables with more than 524288 elements."
But you can use the "openvar"-function to open certain parts:
openvar('large(:,:,1)'); %# pass the argument as a string.
This will open the first "layer" of matrices in your Variable Editor (a 500x500 matrix in this case). This is useful if you need to look into certain parts of a large variable.
Of course you can always define new variables that contain subsets of your larger variable:
less_large = large(:,:,1);
... and then open "less_large" in the variable editor by double clicking on it in the workspace-window. But sometimes the "openvar"-method is a bit faster/easier.

You have a few options. Starting from a clear workspace, you could load the mat file into the workspace. Anything now in the workspace is in the mat file. You can use the variable viewer or parse with scripts.
If you have the Simulink toolbox, you can use Simulink.saveVars to save the contents of the workspace to a human readable m-script that would generate the same contents. It's a shame that you need Simulink to do this, as this function has nothing to do with Simulink.

How about after loading the data, and use whos to display the variables in current workspace? Note that you may want to clear all the other variables before displaying them.

Related

Issue reading .txt file in Matlab. I want to get an array from this file without the unnecessary info it contains

I'm having trouble reading a .txt file to get some data. I want to be able to change some of the values this data contains.
At first, I used this:
A=importdata('myfile.txt');
And got this cell array:
Now what I want is this:
1) Get rid of the headers (the information from cell 1 to 22). That could be easily done by simple indexing (creating a sub-array using just the info from cell 23 to the end of the file).
2) I want to separate the information into different cells, using these identifiers. But I don't know how to separate them into different cells of the array.
'# item bepoch ecode label onset diff dura b_flags a_flags enable bin'
3) Do the same in step 2 to fill those columns with the data in the rest of the cells.
I'm trying to use this approach, but I'm not getting the expected results.
If someone can help me, I'd be glad.
Have you tried dragging the file into the variable workspace window and using the data import wizard? It has some nice features that normally take care of what you are trying to do automatically. Unfortunately, it seems that your text file may have unconventional spacing, but Matlab may be able to handle it if you set the delimeter to ' ' or suchlike.

Loading Matlab matrix into Labview array

I have a matrix which contains GPS waypoints (4 columns - lat,long,h,time) and I would like to use this in a Labview programme to control a UAV.
The code I am working from has a waypoint array to input the waypoints manually from the front panel, but I would like to load this set of points.
I have never used Labview before, so I am having trouble modifying the programme.
Thanks!
Elaborating on a comment, one way that you could do this is to save your MATLAB matrix in a format that you can easily read in LabVIEW, for instance CSV. In MATLAB, save your matrix to a CSV file:
csvwrite(filename, mymat)
where filename is whatever you want it to be surrounded by quotes, e.g. 'GPS_data.csv', and mymat is your data. Then in LabVIEW you can read the contents of the file into a 2D array using Read From Spreadsheet File.vi. Each row of the resulting 2D matrix will a single waypoint, and you can process that data however you see fit. An example that does nothing but display each row after a short delay is shown below.
You could hard-code the filename that you want to read into the Read From Spreadsheet File.vi, or execute your VI without anything wired in to be prompted for a CSV file to read.

Octave/GRASS GIS .mat import error: 'map_data' undefined

I have a Matlab script that calculates a certain terrain-parameter (describing the theoretical shelter from and exposure to wind) based on a digital terrain model. The script works both in Matlab and Octave and yields a matrix.
Now: I am trying to couple this with a GRASS GIS shell script. I can call the script from GRASS, but I have problems getting the output back into GRASS. One way is to use the .mat format. The problem is, however: When I export the result of the calculation (with save -mat4-binary result.mat ans) and try to import the .mat file into GRASS, the error is:
ERROR: No 'map_data' array found in [...file]
Similarly, when I load the file in Octave and try to display it
load result.mat
imagesc(map_data), axis equal, axis tight, colorbar
the error is
error: `map_data' undefined near line 19 column 9
error: evaluating argument list element number 1
When I export from Matlab, it is the same problem.
Where is the bug?
Any help is greatly appreciated.
The "bug" is, your mat-file does not contain any variable named "map_data", I would guess your variable in the mat-file is named "ans". I would use res=load result.mat, then you get a struct with everything which is in the mat file. If you type in res. autocomplete should list all variables inside the struct (not sure about octave), alternatively use fieldnames(res) to list all variable names.
/Update:
I took a short look into the documentation of grass. It expects predefined variable names, all beginning with map_*. Instead of
save -mat4-binary result.mat ans
you should rename your variables to match the documentation and save them using
save -mat4-binary result.mat map_*

.obj file format - alternates between different data types

I'm writing a method to parse the data in wavefront obj files and I understand the format for the most part, however some things are still a bit confusing to me. For instance, I would have expected most files to list all the vertices first, followed by the texture and normal map coordinates and then the face indices. However, some files that I have opened alternate between these different sections. For instance, one .obj file I have of the Venus de Milo (obtained here: http://graphics.im.ntu.edu.tw/~robin/courses/cg03/model/ ) starts off with the vertices (v), then does normal coordinates (vn), then faces (f), then defines more vertices, normals and faces again. Why is the file broken up into two sections like this? Why not list all the vertices up front? Is this meant to signify that there are multiple segments to the mesh? If so, how do I deal with this?
Because this is how the file format was designed. There is no requirement for a specific ordering of the data inside the OBJ, so each modelling package writes it in its own way. Here is one brief summary of the file format, if you haven't read this one yet.
That said, the OBJ format is quite outdated and doesn't support animation by default. It is useful for exchanging of static meshes between modelling tools but not much else. If you need a more robust and modern file format, I'd suggest taking a look at the Collada format or the FBX.
not an direct answer but it will be unreadable in comment
I do not use this file-format but mesh segmentation is usually done for these reasons:
more easy management of the model for editing
separation of parts of model with different material or texture properties
mainly to speed up the rendering by cut down unnecessary material or texture switching
if the mesh has dynamically moving parts then they must be separated
Most 3D mesh file formats contains also transform matrix for each mesh part and some even an skeleton hierarchy
Now how to handle segmented meshes:
if your engine supports only unsegmented models then merge all parts together
This will loose all the advantages of segmented mesh. Do not forget to apply transform matrices of sub segments before merging
or you can implement mesh segmentation into your model class
By adding model hierarchy , transform matrices , ...
Now how to handle mixed model fileformat:
scan file for all necessary chunks of data
remember if they are present
also store their size,and start address in file
and do not forget that there may be more that one chunk of the same data type
preallocate space for all data you need
load/merge all data you need
load chunks of data to you model classes or merge it to single model
of course check if all data needed id present like number of points match number of normals or texture coords ...

Cut a jpg file in C, (NOT crop)

i would like to know how can i cut a jpg file using a coordinates i want to retrieve using artoolkit and opencv, see:
Blob Detection
i want to retrieve coordinates of the white sheet and then use those coordinates to cut a jpg file I'm took before.
Find this but how can this help?
How to slice/cut an image into pieces
If you already have the coordinates, you might want to deskew the image first:
http://nuigroup.com/?ACT=28&fid=27&aid=1892_H6eNAaign4Mrnn30Au8d
This post uses cv::warpPerspective() to achieve that effect.
The references above use the C++ interface of OpenCV, but I'm sure you are capable of converting between the two.
Second, cutting a particular area of an image is known as extracting a Region Of Interest (ROI). The general procedure is: create a CvRect to define your ROI and then call cvSetImageROI() followed by cvSaveImage() to save it on the disk.
This post shares C code to achieve this task.

Resources