How can I change the arrangement of values and plot them?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am working on a project using Matlab's GUI. However, there was a problem. I'd like to retrieve the value of the text file as shown in the first picture. However, the results are printed like the second picture. I want the same result as the third picture. What should I do? With str2double, the NaN value is output. And my final goal is to plot these values. help :(
used code
str = extractFileText('uncoded_BER.txt');
assignin('base', 'str', str);
6 Kommentare
Hiro Yoshino
am 30 Mai 2022
If you have multiple data
data=readtable("uncoded_BER.txt")
data.var1
would be userful as you can access multiple columns easily.
Antworten (1)
Yash
am 15 Nov. 2023
Hello,
I understand that you are interested in importing the the data from a text file as a matrix (or array) and plotting it. Currently, you are using the "extractFileText" function, which reads the entire text from the file and stores it as a string. In your case, it is '-1.5093\n3.4562' where '\n' represents the new line character. This can't be converted to an array using the "str2double" function as it is not in a proper numeric form. Hence you are getting NaN.
There are several other functions you can utilize to import data as a matrix (or array). A few of them are listed below:
1. "importdata" - This can be used to load data from a file as a matrix. The documentation is available at the following link: https://www.mathworks.com/help/matlab/ref/importdata.html
A = importdata('uncoded_BER.txt')
2. "load" - This function is used to load variables from a file into the workspace. Refer to the following link for the documentation: https://www.mathworks.com/help/matlab/ref/load.html
A = load('uncoded_BER.txt')
3. "readmatrix" - This function is specifically designed to read a matrix from a file. You can refer the documentation here: https://www.mathworks.com/help/matlab/ref/readmatrix.html
A = readmatrix('uncoded_BER.txt')
4. "readtable" - This function creates a MATLAB table from a file. This would be beneficial if you have multiple data labellled columnwise. The documentation is available at the following link: https://www.mathworks.com/help/matlab/ref/readtable.html
TBL = readtable('uncoded_BER.txt')
A = TBL.Var1
You can use "textscan" as well, refer to the below MATLAB Answer for an example:
Once you have successfully imported the data as a matrix or array, you can use the "plot" function to visualize it. Refer to the documentation of the plot function at the following link: https://www.mathworks.com/help/matlab/ref/plot.html
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!