Effacer les filtres
Effacer les filtres

Read notepad into a variable

2 vues (au cours des 30 derniers jours)
rockstar49
rockstar49 le 25 Mai 2023
Hi,
Id like to read a notepad file row and make that into a variable
txt{6}(1:end-1)=File(cals,txt{6}(1:end-1)); (says Conversion to char from struct is not possible)
I can run this command: txt{6}(1:end-1) and it would give me, ans="x"
i can also run A=File(cals,txt{6}(1:end-1)); and it would output a 1 by 1 structure with a value inside it.
Any suggetions?
Do i need to use eval? etc
Thank you!
  7 commentaires
Steven Lord
Steven Lord le 25 Mai 2023
How did you create the variable named txt?
rockstar49
rockstar49 le 26 Mai 2023
I used importdata (notepad file)

Connectez-vous pour commenter.

Réponses (2)

Diwakar Diwakar
Diwakar Diwakar le 25 Mai 2023
% Specify the path to the text file
filePath = 'path/to/your/file.txt';
% Read the text file
fileData = fileread(filePath);
% Split the file contents by newline character to get individual rows
rows = split(fileData, '\n');
% Select the desired row (in this example, row number 6)
rowIndex = 6;
selectedRow = rows{rowIndex};
% Display the selected row
disp(selectedRow);
% Store the selected row in a variable
myVariable = selectedRow;
You are trying to assign its value to the variable txt{6}(1:end-1) directly, which is causing the error. Try this code.
  8 commentaires
Stephen23
Stephen23 le 27 Mai 2023
Just use READCELLS or READLINES or similar.
Walter Roberson
Walter Roberson le 27 Mai 2023
An example extract from the file would help.
As would a clearer description of what you are trying to do with the information.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 28 Mai 2023
Try
textLines = readlines(fileName);
If you have any more questions, then attach your text file with the paperclip icon after you read this:

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by