I want to write a C++ program that reads the contents of a file word by word and puts them into a vector of strings. The program then prints to the screen all the words in the vector each on its line, the total number of words read and then clears all the words from the vector. Could someone please help me on this.
Related
I want to avoid repetitions as much as possible. I've run the same Matlab program that uses "random" numbers multiple times and gotten exactly the same results. I learned that I should put the command shuffle at the beginning, and then the program will replace the default seed with a new one, based on the time on the clock. But the sequence of outputs from the pseudo-random number generator will
still contain a pattern.
I recently learned about a quantum box random number generator (this or something like it), and in the process of looking it up online I found a couple web servers that deliver random numbers that are continuously generated by quantum mechanical means: ANU Photonics and ANU QRNG.
To buy a quantum box looks pretty hard to afford, so how might I integrate one of the online servers into Matlab?
On http://qrng.anu.edu.au, click the "download" link in the text, and it takes you to a FAQ page where it tells what to download to use the random number generator in different ways. The last on the list is Matlab, for which it gives a link to directly download some code to access the random numbers and a link to Matlab Central to download the JSON Parser which is necessary for it to work.
The code is very simple, and as a script only displays the values it fetches, but can easily be turned into a function. I unzipped the contents of parse_json.zip into C:/Program Files/MATLAB/[version]/toolbox/JSONparser, a new folder in the Toolboxes, navigated to the Toolboxes in the Current Folder in Matlab, right clicked JSONparser, and clicked Add to Path.
Read the comments on the Matlab Central page for JSON Parser to get an idea of the limits of how many random numbers you can pull down at a time.
The random numbers are 16-bit non-negative integers; to create a random integer with more bits, say, 32 bits, I'd recommend taking two of these integers, multiplying one by 2^16, and adding them. If you want a number between 0 and 1, divide the sum by 2^32.
I have extracted corner points using detectMinEigenFeatures and then have extracted the feature descriptions using extractFeatures. Now I want to write the feature description in an excel sheet. But I can't write. When I use xlswrite it shows an error mentioning only numeric and logical matrices can be written in excel. Can any one suggest me a way to store the feature points in excel?
It would be hard to write the contents of a binaryFeatures object into an excel sheet. Each descriptor is a string of bits, not a vector of numeric values.
I have a CSV file where I have decimal numbers like 1.1, 1.10, 1.100. When I load the file in Matlab using importdata or even textscan, it show all these numbers same: 1.1 discarding 0's at the end. But, I have different meaning of them.
Is there anyway to recover?
Thanks,
Sam
You're saying you mean something different by 1.1 than by 1.100000? Mathematically, they are the same number (I sincerely hope you know this already).
So if your "numbers" don't have the same meaning as numbers in any of the strictly defined mathematical number systems (which MATLAB normally assumes is the case), you should import them as strings (%s) rather than numbers (%d, %f, etc.), and process them as such.
I've asked this before, but I feel I wasn't clear enough so I'll try again.
I am running a network simulation, and I have several hundreds output files. Each file holds the simulation's test result for different parameters.
There are 5 different parameters and 16 different tests for each simulation. I need a method to store all this information (and again, there's a lot of it) in Matlab with the purpose of plotting graphs using a script. suppose the script input is parameter_1 and test_2, so I get a graph where parameter_1 is the X axis and test_2 is the Y axis.
My problem is that I'm not quite familier to Matlab, and I need to be directed so it doesn't take me forever (I'm short on time).
How do I store this information in Matlab? I was thinking of two options:
Each output file is imported separately to a different variable (matrix)
All output files are merged to one output file and imprted together. In the resulted matrix each line is a different output file, and each column is a different test. Problem is, I don't know how to store the simulation parameters
Edit: maybe I can use a dataset?
So, I would appreciate any suggestion of how to store the information, and what functions might help me fetch the only the data I need.
If you're still looking to give matlab a try with this problem, you can iterate through all the files and import them one by one. You can create a list of the contents of a folder with the function
ls(name)
and you can import data like this:
A = importdata(filename)
if your data is in txt files, you should consider this Prev Q
A good strategy to avoid cluttering your workspace is to import them all into a single matrix. SO if you have a matrix called VAR, then VAR{1,1}.{1,1} could be where you put your test results and VAR{1,1}.{2,1} could be where you put your simulation parameters of the first file. I think that is simpler than making a data structure. Just make sure you uniformly place the information in the same indexes of the arrays. You could also organize your VAR row v col by parameter vs test.
This is more along the lines of your first suggestion
Each output file is imported separately to a different variable
(matrix)
Your second suggestion seems unnecessary since you can just iterate through your files.
You can use the command save to store your data.
It is very convenient, and can store as much data as your hard disk can bear.
The documentation is there:
http://www.mathworks.fr/help/techdoc/ref/save.html
Describe the format of text files. Because if it has a systematic format then you can use dlmread or similar commands in matlab and read the text file in a matrix. From there, you can plot easily. If you try to do it in excel, it will be much slower than reading from a text file. If speed is an issue for you, I suggest that you don't go for Excel.
I need your help. I have more than 40000 proteins in fasta file format.
First I want to write a function:
that is able to calculate the masses of the b- and y-ions
that creates a peptide database from the target proteins (mat-file)
that creates a peptide database coming from the decoy proteins (mat-file)
Then, I want to:
load the observed data
filter the peptide databases for candidate peptides given a certain ppm accuracy
write a function that scores the candidate peptides against the observed data
Come up with a thresholding scheme to discern bonafide peptide spectrum matches from the bogus ones
To get started with, FASTA is text file format. To write text files check MATLAB documentation of fopen, fprintf and fclose. To load the text from the data files you've written you can use fopen, fscanf and fclose. Actually, MATLAB has fastainfo, fastaread and fastawrite too. You should check MATLAB documentation of these commands and of other FASTA-related and protein analysis related commands which could be useful for you (I haven't done protein analysis, so I can't say which are the ones you'll need).
Further, you are asking so many things in one question that it's not possible to answer them all, because your question IMHO is kind of "How I write my entire program?". But I think that you could get started with the commands I have listed, and when you have some code written and a well-defined problem that you've attempted to solve yourself, then you could post a new question about it, with the relevant parts of your code.
MATLAB's Bioinformatics Toolbox contains building block routines that you can put together to achieve this. If you have a specific problem when putting them together, post the specific question.