how to import data from .tvf file

3 views (last 30 days)
Utku Yigit
Utku Yigit on 23 Mar 2022
Commented: Walter Roberson on 9 Oct 2024
I want to import the data found from column 121 to 131 column for x axes, from column 121 to 26625. For y axes, from 130 row 82 column to 130 row 16405 for y axes.
  1 Comment
Walter Roberson
Walter Roberson on 23 Mar 2022
I didn't think anyone still used dBase Table View Settings files ???

Sign in to comment.

Answers (1)

Arjun
Arjun on 9 Oct 2024
Edited: Arjun on 9 Oct 2024
I see that you want to load and access .TVF file for some data manipulation.
Importing data from a .TVF file, which is not a standard format like .CSV or .XLSX, is a bit tricky and hence requires clear understanding of the file structure. As nothing is mentioned about the file, it has been assumed that it is a text-based tabular file with tab separated values. You can use “fopen” to open the file, “textscan” to access the contents of the file and then convert it to a matrix using “cell2mat” for easy indexing of the data.
As an illustration .TVF file generation code and manipulation code are shown below which will give better clarity over handling .TVF files.
Kindly refer to the code for generating a .TVF file:
filePath = 'sample.tvf';
numRows = 200;
numCols = 150;
sampleData = rand(numRows, numCols);
% Open the file for writing
fileID = fopen(filePath, 'w');
if fileID == -1
error('Failed to create the file.');
end
% Write data to the file
for i = 1:numRows
% Convert each row to a tab-separated string
rowString = sprintf('%f\t', sampleData(i, :));
rowString = rowString(1:end-1); % Remove trailing tab
% Write the row to the file
fprintf(fileID, '%s\n', rowString);
end
fclose(fileID);
disp(['Sample .tvf file created: ', filePath]);
Kindly refer to the code for loading and accessing the .TVF file:
% Define the file path
filePath = 'sample.tvf';
% Open the file
fileID = fopen(filePath, 'r');
disp(fileID);
if fileID == -1
error('Failed to open the file.');
end
% Read the entire file into a cell array
data = textscan(fileID, repmat('%f', 1, 131), 'Delimiter', '\t', 'HeaderLines', 0);
% Close the file
fclose(fileID);
% Convert cell array to matrix for easier indexing
dataMatrix = cell2mat(data);
xData = dataMatrix(1:180, 51:61);%manipulate as per need
yData = dataMatrix(130, 82:85);% manipulate as per need
disp(['Size of xData: ', mat2str(size(xData))]);
disp(['Size of yData: ', mat2str(size(yData))]);
% Clear temporary variables
clear data dataMatrix
Kindly go through the documentation links for better understanding :
I hope this will help!

Tags

Community Treasure Hunt

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

Start Hunting!