mat-file

How to preserve matlab struct when accessing in python?

前提是你 提交于 2019-12-03 06:17:50
I have a mat-file that I accessed using from scipy import io mat = io.loadmat('example.mat') From matlab, example.mat contains the following struct >> load example.mat >> data1 data1 = LAT: [53x1 double] LON: [53x1 double] TIME: [53x1 double] units: {3x1 cell} >> data2 data2 = LAT: [100x1 double] LON: [100x1 double] TIME: [100x1 double] units: {3x1 cell} In matlab, I can access data as easy as data2.LON, etc.. It's not as trivial in python. It give me several option though like mat.clear mat.get mat.iteritems mat.keys mat.setdefault mat.viewitems mat.copy mat.has_key mat.iterkeys mat.pop mat

How can I check the contents of a MAT-file in MATLAB without loading it?

让人想犯罪 __ 提交于 2019-12-03 05:45:53
I have a large structure in a MAT-file. I want to check if a specific field is present in the structure without loading the MAT-file since the contents are very large and I want to minimize memory use. Is this possible, or must I load it first like in the following example?: load('test.mat'); %# Load the MAT-file tf = isfield(s,'fieldname'); %# Check if structure s has field 'fieldname' To check the contents of a MAT file without loading it, use: vars = whos('-file','test.mat') ismember('fieldname', {vars.name}) Jonas As far as I know, you have to load the file in order to be able to check if

How to transfer Nifti file into .mat Matlab file?

时光毁灭记忆、已成空白 提交于 2019-12-02 20:10:20
问题 I have a Nifti file, the size of which is 62*62*38. How can I transfer the Nifti file to .mat Matlab file? 回答1: This can read NIFTI as well as many other medical image file types into MATLAB arrays, which you can then save as .mat files. 回答2: Most medical imaging data can be manipulated effectively using some kind of toolbox, such as SPM. However, if you need to gain access to the raw matrix I've always used NIfTI tools from the Mathworks file exchange site (here). There are two functions

How to save a figure in a MAT-file?

允我心安 提交于 2019-12-02 11:29:16
问题 I want to save the image in a figure directly as a 256x256 size MAT-file. However, I found that the saved MAT-file sizes were different, and when using imagesc to display the image, it seemed to be a little different from the original image. I will show my code and hope someone could help me to solve it. spectrogram(x,window,L,N,fs); set(gcf,'position',[500,500,205,205]); set(gca,'Position',[0 0 1 1]); f=getframe(gcf); mat=getimage(gcf); save(['D:\matlab\speech\mydata\cleanmat\',strcat

How to transfer Nifti file into .mat Matlab file?

牧云@^-^@ 提交于 2019-12-02 10:11:36
I have a Nifti file, the size of which is 62*62*38. How can I transfer the Nifti file to .mat Matlab file? This can read NIFTI as well as many other medical image file types into MATLAB arrays, which you can then save as .mat files. Most medical imaging data can be manipulated effectively using some kind of toolbox, such as SPM. However, if you need to gain access to the raw matrix I've always used NIfTI tools from the Mathworks file exchange site ( here ). There are two functions that are relevant here: load_nii and load_untouched_nii . The first function load_nii takes care of situations

How to save a figure in a MAT-file?

我与影子孤独终老i 提交于 2019-12-02 05:40:20
I want to save the image in a figure directly as a 256x256 size MAT-file. However, I found that the saved MAT-file sizes were different, and when using imagesc to display the image, it seemed to be a little different from the original image. I will show my code and hope someone could help me to solve it. spectrogram(x,window,L,N,fs); set(gcf,'position',[500,500,205,205]); set(gca,'Position',[0 0 1 1]); f=getframe(gcf); mat=getimage(gcf); save(['D:\matlab\speech\mydata\cleanmat\',strcat(int2str(i)),'.mat'],'mat','-v6'); save doesn't do anything unexpected here. The issue is that the direction

Python to MATLAB: exporting list of strings using scipy.io

喜欢而已 提交于 2019-12-01 02:46:11
I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical matrices (which I learned to do here ) and text cell arrays. I tried: import scipy.io my_list = ['abc', 'def', 'ghi'] scipy.io.savemat('test.mat', mdict={'my_list': my_list}) In MATLAB, I load test.mat and get a character array: my_list = adg beh cfi How do I make scipy.io export a list into a MATLAB cell array? You need to make my_list an array of numpy objects: import scipy.io import numpy as np my_list = np.zeros((3,),

How to save Sift feature vector for classification using Neural network

那年仲夏 提交于 2019-12-01 01:53:13
Matlab implementation of SIFT features were found from http://www.cs.ubc.ca/~lowe/keypoints/ . with the help of stackoverflow. I want to save features to a .mat file. Features are roundness, color, no of white pixel count in the binary image and sift features. For the sift features I took descriptors in above code { [siftImage, descriptors, locs] = sift(filteredImg) } So my feature vector now is FeaturesTest = [roundness, nWhite, color, descriptors, outputs]; When saving this to .mat file using save('features.mat','Features'); it gives an error. Error is like this. ??? Error using ==> horzcat

Python to MATLAB: exporting list of strings using scipy.io

人走茶凉 提交于 2019-11-30 22:36:11
问题 I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical matrices (which I learned to do here) and text cell arrays. I tried: import scipy.io my_list = ['abc', 'def', 'ghi'] scipy.io.savemat('test.mat', mdict={'my_list': my_list}) In MATLAB, I load test.mat and get a character array: my_list = adg beh cfi How do I make scipy.io export a list into a MATLAB cell array? 回答1: You need

deleting variables from a .mat file

匆匆过客 提交于 2019-11-30 17:22:43
Does anyone here know how to delete a variable from a matlab file? I know that you can add variables to an existing matlab file using the save -append method, but there's no documentation on how to delete variables from the file. Before someone says, "just save it", its because I'm saving intermediate processing steps to disk to alleviate memory problems, and in the end there will be almost 10 GB of intermediate data per analysis routine. Thanks! Interestingly enough, you can use the -append option with SAVE to effectively erase data from a .mat file. Note this excerpt from the documentation