looking to compare lines of text putting them into an array ( counting the lines in the txt file ) to then compare a user input to the number of lines in the array from the txt file ( I hope that makes sense ) I am confused as to how to do this ?
Thank you for your time and assistance / ideas on this
Related
I need to write this line into .txt file
連携データの取得に失敗しました。
This is my code
echo 連携データの取得に失敗しました。>>%File_name%
And this is result
連携デーモフ取得に失敗しました。
4th and 5th character had change, I have no idea about this. Can someone explain to me what's happen?
So I have to write a C program to read data from .csv files supplied to me by multiple users, into matrices on which I will perform some operations (like matrix addition, multiplication with necessary conditions on dimensions, etc.) and print these matrices (or the output data) in to .csv files again.
I also need to dynamically allocate memory to my matrices.
Now, I have zero background in dealing with .csv files. I do not at all know the required code to read a .csv file or write into a .csv file. I have searched for long on the Internet but surprisingly I have not found any program that teaches how to deal with .csv files from the elementary level.
I am lost on this and need a lot of guidance, maybe a sample, fully well-written C program as I need a comprehensive example to begin with.
A CSV file is just a plain ASCII text file that contains a grid of values. Think of the file as a set of rows in a database table where each line in the file represents one record and the order of the data in each line is identical. Each item of data is separated using a comma character (hence the name). So to read the file:-
open file
until the end of the file
read line into a string
split the string into sub strings where ',' is the dilimiter
parse each sub string
Since there is no formatting information in a CSV file, if the data in each value consists of a string, then what do you do if the value has a comma in it? For reading numbers that is not a problem for you.
You could read the file in several passes, the first to determine the amount of data there is (number of columns, number of rows, etc) and the second to actually read the data.
Writing the CSV is quite simple:-
open file
for each record to write
for each element to write
write element
if not last element
write a comma
write a new line
Does anyone know how to read a .txt file from Mathematica in lines and save those lines as elements from an array? The file I'm trying to read are names like this:
Brad Pitt
Scarlet Johanson
Woody Allen
etc
I have no experience with Mathematica by the way, thanks.
ReadList["filename.txt", String] is the command that reads a file called filename.txt and puts each line, as a string, into a List (which is an array).
If you are on Windows and your text file is named C:\dir\names.txt, then you can use
names = StringSplit[Import["C:/dir/names.txt"], "\n"]
to import the file, and then split the resulting string at the end of each new line into an array of strings. Note the different direction of the slashes.
If you aren't on Windows, the command is the same, but the directory won't be prefixed with a drive letter.
I am trying to take an input from a text file in this format:
Processed_kplr010074716-2009131105131_llc.fits.txt
Processed_kplr010074716-2009166043257_llc.fits.txt
Processed_kplr010074716-2009259160929_llc.fits.txt
etc.... (there are several hundred lines)
and use that input to name my output files for a Matlab loop. Each time the loop ends, i would like it to process the results and save them to a file such as:
Matlab_Processed_kplr010074716-2009131105131_llc.fits.txt
This would make identifying the object which has been processed easier as I can then just look for the ID number and not of to sort through a list of random saved filenames. I also need it to save plots that are generated in each loop in a similar fashion.
This is what I have so far:
fileNames = fopen('file_list_1.txt', 'rt');
inText = textscan(fileNames, '%s');
outText = [inText]';
fclose(fileNames)
for j:numel(Data)
%Do Stuff
save(strcat('Matlab_',outText(j),'.txt'))
print(Plot, '-djpeg', strcat(outText(j),'.txt'))
end
Any help is appreciated, thanks.
If you want to use the save command to save to a text file, you need to use -ascii tab, see the documentation for more details. You might also want to use dlmwrite instead(or even fprintf, but I don't believe you can write the whole matrix at once with fprintf, you have to loop over the rows).
I'm working on a programming assignment and I was wondering if somebody could help me out with this issue. This assignment says to write a program in Prolog which takes the text from an input text file and write it to an output text file. In order to get the location of the text files, the user needs to be prompted to write the path of the text files.
I have figured out how to do it, but I have one small issue that is really annoying. Here is my code:
main:-
%Ask the user for the input text file and then open the file
write('Please enter the filename you would like to read from:'),
nl,
read(X),
open(X,read,In),
%Ask the user for the output text file and then open the file
write('Please enter the filename you would to write to:'),
nl,
read(Y),
open(Y,write,Out),
%Read in characters from the input text file and then put them
%on the output text file.
tell(Out),
repeat,
get_char(In,T),
write(T),
T == end_of_file, !,
close(In),
told,
close(Out).
Let's say the text file that is going to be read says "this is a test". My issue is if I use the program to save this text and write it to another text file, it will write "this is a testend_of_file" instead.
I realize that this is happening because the loop isn't being terminated at the right time, but I'm not sure how to go about fixing the loop so "end_of_file" doesn't get accidentally written to the text file as well. Any help would be much appreciated. I feel like I've tried everything.
You first do write(T), and after that your testing for T == end_of_file, so no surprise end_of_file will be written.
Try ( T == end_of_file -> ! ; write(T), fail ),
What Prolog system are you using, BTW?