Deleting the same empty row in 2 different column vectors - then searching a value giving the other column vector result

Quite easy for some more experanced then me, still learning Matlab.
Hoping someone could help.
From the file attached, I am trying to do the following......
  1. From row DTCs I would like to delete the rows with [ ] and delete the corresponding rows in FlowID
2.Then, lets say I wanted to search for "P22D5-37" in DTCs, I would like the program to give me all the values from FlowID values

 Respuesta aceptada

load_mapping_csv
Mapping_refine=Mapping(~strcmp(Mapping(:,3),'[]'),[1:3]);
The script of load_mapping_csv is attached, and has been prepared using matlab automatic script to load data from csv files: Home > Import Data
If you have only one search query, you can use this
search_query='P22D5-37';
Mapping_refine(contains(Mapping_refine(:,3),search_query),:)
If you have multiple queries, you can use cellfun function to iterate over all cell elements.
One can use Mapping_search_query or Mapping_search_query_merged to see the results from different perspective.
search_queries={'P22D5-37','U0064-88'}
Mapping_search_query=cellfun(@(x) Mapping_refine(contains(Mapping_refine(:,3),x),:), search_queries,'uni',0)
cat(1,Mapping_search_query{:})

14 comentarios

Just checking this, so far seems great - THANK YOU!
Is there a way of doing part 2?
2.Then, lets say I wanted to search for "P22D5-37" in DTCs, I would like the program to give me all the values from FlowID values
I am getting this error.....
nayan
nayan el 14 de Mzo. de 2021
Editada: nayan el 14 de Mzo. de 2021
This is perfect - Thank you!!
Could you lastly delete the replica - only need to know the value, dont require all of them....
You can first find the unique values in the column 2, and then find the correspoding indices, eventually seelcting only the last index.
Mapping_search_query_merged=cat(1,Mapping_search_query{:});
unique_vals=unique(cell2mat(Mapping_search_query_merged(:,2)),'stable');
unique_vals_index= cellfun(@(x) x(end),arrayfun(@(x) find(cell2mat(Mapping_search_query_merged(:,2))==x) ,unique_vals,'uni',0));
Mapping_search_query_merged(unique_vals_index,:)
Hope it helps.
Thanks but im getting an error,
Undefined function or variable 'Mapping_search_query_merged'.
Mapping_search_query_merged=cat(1,Mapping_search_query{:});
I save the cat output in Mapping_search_query_merged.
Thanks, but the same error message is appearing?!
You must have deleted a part of code. Please refer to the below complete code.
clc
clear
load_mapping_csv
Mapping_refine=Mapping(~strcmp(Mapping(:,3),'[]'),[1:3]);
search_queries={'P22D5-37','U0064-88'}
Mapping_search_query=cellfun(@(x) Mapping_refine(contains(Mapping_refine(:,3),x),:), search_queries,'uni',0)
Mapping_search_query_merged=cat(1,Mapping_search_query{:});
unique_vals=unique(cell2mat(Mapping_search_query_merged(:,2)),'stable');
unique_vals_index= cellfun(@(x) x(end),arrayfun(@(x) find(cell2mat(Mapping_search_query_merged(:,2))==x) ,unique_vals,'uni',0));
Mapping_search_query_merged(unique_vals_index,:)
Hope this helps.
You my friend are a genius!!
Thank you for this...I need to dissect and learn how you did this.
Again thank you bud!
Hey,
wondering if you could help alittle more - wanted to further this work by taking in a second file (attached).
I would like to use the numbers on the LEFT (unique_vals) and compare them to the case numbers on the RIGHT. Any number which doesnt match the RIGHT then numbers on the LEFT (nique_vals) are deleted.
Attached is the script of load_compare_csv.m, which has been Auto-generated by MATLAB.
load_compare_csv
CompareCasevals=cell2mat(CompareCase);
new_unique_vals=unique_vals(cellfun(@length, arrayfun(@(x) find(CompareCasevals==x),unique_vals,'uni',0))~=0)

Iniciar sesión para comentar.

Más respuestas (1)

Following the instructions, I am getting this error message...?

1 comentario

Figured it out, I just uploaded the table myself and used the code you provided...THANK YOU mate, your work help me loads!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Mzo. de 2021

Comentada:

el 26 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by