フィルターのクリア

How can I change the arrangement of values and plot them?

2 ビュー (過去 30 日間)
건희 이
건희 이 2022 年 5 月 30 日
回答済み: Yash 2023 年 11 月 15 日
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 件のコメント
Hiro Yoshino
Hiro Yoshino 2022 年 5 月 30 日
If you have multiple data
data=readtable("uncoded_BER.txt")
data.var1
would be userful as you can access multiple columns easily.
건희 이
건희 이 2022 年 6 月 1 日
thank you!! complet!!

サインインしてコメントする。

回答 (1 件)

Yash
Yash 2023 年 11 月 15 日
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!

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by