Trouble using strcmp in Matlab
Show older comments
Background
I have two datasets and I want to write a function that takes only the data from the two datasets that is in common between the two.
Basically, I currently only have data for a few people and I will be getting the data for the other users later. The issue is that I might not get data for all the users so I need my script to reflect that reality so I need to make the script for now take only data from users that I have data available for.
In addition, there are just random users that show up in the dataset that can't be in the final dataset so that is why I'm going out of my way right now to address this issue. The dataset will get very large as we get more users so that's why I'm doing this.
Introducing... the two datasets I have:
"Users.xlsx"
This dataset has information on ALL the users possible.
"Task.xlsx"
This dataset only has information on a few of the users.
Code
This is the code that I've been trying so far and I haven't been able to get it to work:
root_folder = %put file path in ''
users = readtable([root_folder filesep 'Users.xlsx']);
task = readtable([root_folder filesep 'Task.xlsx']);
for sub=1:length(users.UserId)
Opt_Sub = task(strcmp(task.UserId,users.UserId{sub}),:);
end
Each time I run this command, I get an empty table. What I'm basically trying to do is use strcmp to compare between the two datatables and find out which columns are 1s and 0s (with 1 showing up in both columns). If something is in common in both columns, then I use task(...) to get all the common data points.
If anyone has a solution, please let me know. Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!