Question:
Help solve this matlab problem using files?
CQ3040
2010-06-25 17:09:34 UTC
% The function takes in two file names, with the first specifying a file
% encoded using the caesar cipher, and the second specifying a
% comma-separated values (csv) file containing the shifts necessary to
% decode each line. The function will then write out a new text file that
% has each line of the encoded file decoded. The file name of the decoded
% file will be identical to the encoded file name, except that the string
% 'decoded_' will be appended to the front. The decoded file will only
% use the '\n' character to specify new lines, and the last line of the
% decoded file will not contain a new line character.

how do i start this problem?
im so confused on using files with matlab
Three answers:
mhnd_79
2010-06-25 17:32:19 UTC
first how to write something into a file



Write a short table of the exponential function to a text file called exp.txt:

x = 0:.1:1;

y = [x; exp(x)];

% open the file with write permission

fid = fopen('exp.txt', 'w');

fprintf(fid, '%6.2f %12.8f\n', y);

fclose(fid);



and for reading out the csv file (the shifts) you can use

shifts = textread(theCsvFileName, '%d', 'delimiter', ',');



and finally for reading reading the lines into a string array

lines = textread(theEncodedTextFileName, '%s', 'delimiter', '\n');
Heir Kichert
2010-06-25 17:25:31 UTC
as for the csv, the function opencsv(filename) will open the csv and place it into an array. make sure that it only contains numbers though.



for the other file, if it's just a text file, you can load it into a string variable using the fileread function. you can then decrypt the string using the files in combination.
2016-04-12 16:27:15 UTC
Yahoo doesn't allow such long posts (echo 'x' is a lot of lines in assembly), but try doing a web search.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...