How to write data to a csv file in MATLAB? [duplicate] - matlab

This question already has an answer here:
Export data from matlab to csv [duplicate]
(1 answer)
Closed 7 years ago.
I can't seem to find the correct syntax for this. My code loads a file "sensordata.mat" that is called "temps", and uses this for results. At the end of the code it should write my data to a csv file. I tried the following:
writetable('sensordata.csv','temps')
This only gives me an error stating:Undefined function 'write' for input arguments of type 'char'.
Does anyone know the solution for this? Thank you for your expertise.

CSV support is built into MATLAB:
csvwrite('sensordata.csv', temps);

Related

How to save using a default or dynamically generated filename in Matlab? [duplicate]

This question already has an answer here:
Save mat file from MATLAB
(1 answer)
Closed 4 years ago.
How to save using a default or dynamically generated filename in Matlab? I have done something like this below. But my .dat file is saved as filename.dat instead of the filename I generated using sprintf command.
filename = sprintf('k2-%d_k3-%d_k4-%d.dat', K2,K3,K4)
save filename variable -ascii
Here, %d would be replaced by the numbers of those variables K2,K3,K4 in my filename.
Thanks. I have found the solution.
save(filename, 'variable', '-ascii')
does the trick. I had been searching for a while, and it clicks only after I post.

How to find a 1-digit word using regular expression [duplicate]

This question already has answers here:
List all files in a directory given a regular expression / a set of extensions (Matlab)
(3 answers)
Matlab equivalent of `endsWith`: How to filter list of filenames regarding their extension?
(1 answer)
Closed 7 years ago.
I want to be able to detect a file by looking at its extension:
.m,
.fig,
.mdl,
.slx
but not
.mat
or others.
The final use will be to call DIR with a regular expression that filters out all the unnecessary files.
My first obstacle was to define a word of a single character "m". I couldn't figure out which expression should I use for REGEXP, and the documentation of Matlab was not clear enough.
An example of usage will be helpful, and a reference to a more understandable place will be very appreciated.

How to print matlab struct into a text file? [duplicate]

This question already has answers here:
How to save a structure array to a text file
(3 answers)
Closed 8 years ago.
I am an R user: I don't use Matlab. However, I am working with a genomic file from the Broad Institute called "hg18_with_miR_20080407.mat". You can find it at: http://genepattern.broadinstitute.org/ftp/distribution/genepattern/dev_archive/GISTIC/broad.mit.edu:cancer.software.genepattern.module.analysis/00125/1.1/
I tried to use the R package R.matlab (table <- readMat("~/desktop/hg18_with_miR_20080407.mat")), but it keeps loading in definitively. Hence, since I need that file today, I used a friend's computer with Matlab. I have a struct <1x26835> called rg
Each variable has the following values:
refseq 'NM_003585'
gene 'double C2...'
symb 'DOC2B'
locus_id 8447
...
Is there a way that I can print each entry into a text file that I could easily parse? Is there a better way? I am reading the Matlab documentation but would appreciate if someone could give me a one-liner. If not possible, how could I search each variable for a specific gene entry? I keep getting errors. For example:
find(rg == 'Met')
Error: The expression to the left of the equals sign is not a valid target for an assignment.
Thank you!
I recommend trying YAML files (site).
There are libraries for writing matlab data into it here that I have used and liked and googling shows me that there appear to be libraries for R as well.
YAML is basically a newer version of XML files that is human readable, simpler, and less extensible.

how to import data from multiple folders in matlab? [duplicate]

This question already has answers here:
How to get all files under a specific directory in MATLAB?
(8 answers)
Closed 8 years ago.
I have my data in multiple folders. Let's say I have a folder containing 100 subfolders at the moment that look like this:
/folder/Re0001/vitesse
/folder/Re0002/vitesse
/folder/Re000N/vitesse
/folder/Re000N+1/vitesse
/folder/Re0100/vitesse
I want to import the vitesse file into a cell array. This is the code that i am using at the moment:
numfiles=100;
mydata=cell(1,numfiles);
for i=1:numfiles
mydata{i}=uiimport;
end
It is a working solution.
However, if it involves 100 or more files I have to specify each folders and files manually, which is very troublesome.
By the way I am new to Matlab so can you please incorporate example code with the directory given.
I did something similar few days ago. Have a look at the matlab function ls. If you are using windows system, you are all set. If your are using linux, you may need to split the results. However newer version of matlab have the strsplit function that will do the job, or you will use regular expressions.
In your case,
list = ls('/folder/*/vitesse');
will give you a list of your files.

How to read this file in the objective c and pass in the array [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Where can I find a CSV to NSArray parser for Objective-C?
I have the CSV file like this:
vv pp
96.84686 86.38099
How to read this file in the objective c and pass in the array
There are some open source csv parser available search on google for that. you will find one in github. Here is one to help you https://github.com/davedelong/CHCSVParser