필터 지우기
필터 지우기

Loading in a table that has multiple values in a single cell seperated by a comma

조회 수: 3 (최근 30일)
User
User 2023년 10월 17일
편집: Walter Roberson 2023년 10월 26일
Does matlab have an issue when you load in data from a csv file and multiple cells in your file contain more than one value which are seperated by a comma? I am trying to match to columns together from two different csv files that have the same data type but I am getting the issue of "
Error using tabular/ismember
A and B must contain the same variables.'
Is this because some of my cells in one of my csv contain multiple values and matlab is not able to recognize each one of them?

답변 (1개)

Walter Roberson
Walter Roberson 2023년 10월 17일
You are trying to use ismember() to compare two tables directly. ismember() only permits that if all of the same variables occur in each table
Perhaps join would be appropriate for your purpose?
  댓글 수: 2
User
User 2023년 10월 26일
How would I use the join function for this sample data set where I want to use example 2 xlsx and compare it to column 2 of example 1 file. If there is a match I would like it to read its respective value in column 1. Do i have to create a for loop to do this for each sample?
Walter Roberson
Walter Roberson 2023년 10월 26일
편집: Walter Roberson 2023년 10월 26일
Do not ismember entire tables -- select variables from the table.
filename1 = 'example1.xlsx';
filename2 = 'example2.xlsx';
T1 = readtable(filename1, 'VariableNamingRule', 'preserve');
T2 = readtable(filename2, 'VariableNamingRule', 'preserve');
[found, idx] = ismember(T2.('last name'), T1.('last name'));
T1.('first name')(idx(found))
ans = 1×1 cell array
{'ben'}
innerjoin(T1, T2)
ans = 1×2 table
first name last name __________ _________ {'ben'} {'smith'}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by