フィルターのクリア

find equal value into cell

2 ビュー (過去 30 日間)
Greg LANGE
Greg LANGE 2023 年 4 月 23 日
コメント済み: Star Strider 2023 年 4 月 24 日
I try to find the line from table " vehicule2021bis2" with "Num_Acc" corresponding with the same "Num_Acc" in the "lieux2021bis3"
Then I copy certain colon from "lieux2021bis3" into " vehicule2021bis2"
I tried
Wanted = find(vehicule2021bis2.Num_Acc{1}==lieux2021bis3.Num_Acc{:}))
I wrote instead a if with a for with while and iF, which take very long time to
for i=1 :970000
clc
i
line=0;
lol1=height(lieux2021bis3)
j=1;
while j <=lol1
if vehicule2021bis2.Num_Acc{i}== lieux2021bis3.Num_Acc{j}
vehicule2021bis2.catr(i)=lieux2021bis3.catr(j);
vehicule2021bis2.voie(i)=lieux2021bis3.voie(j);
break
else
j=j+1;
end
end
I am convinced to use find or another method will be much more faster.
Same question but with 2 condition
Wanted = find(vehicule2021bis2.Num_Acc{1}==lieux2021bis3.Num_Acc{:}&& vehicule2021bis2.id_vehicule{1}==lieux2021bis3.id_vehicule{:} ))
  2 件のコメント
dpb
dpb 2023 年 4 月 23 日
編集済み: dpb 2023 年 4 月 23 日
fn='https://www.mathworks.com/matlabcentral/answers/uploaded_files/1364343/workspace_cell_value.mat';
load(fn)
Error using load
Unable to read file 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1364343/workspace_cell_value.mat'. If it is a Version 7 or earlier MAT-file, consider saving your data afresh in Version 7.3 MAT-files to access it from a remote location.
whos
Unfortunately, either I don't know how to access a .mat file within the forum or it can't be done with default .mat files...
Star Strider
Star Strider 2023 年 4 月 23 日
@dpb — This is relatively new (within the last couple weeks).
Left-click on the ‘paperclip’ icon, left-click on ‘Link from this thread’ then choose the file and left-click on ‘Submit’. It automatically attaches the selected file to that particular Answer or Comment, then you can use load or any of the others (fileread, readtable, etc.), however it is still necessary to provide the file name. (I right-click on the file name where it’s originally posted, choose ‘Copy link’, then paste it in the appropriate place in the function argument list and edit out everything other than the file name. It’s easier than typing it in most instances, and prevernts misspellings.)
To upload a file from your computer with the ‘paperclip’ icon open, left-click on ‘Choose a file’.
.

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

採用された回答

Star Strider
Star Strider 2023 年 4 月 23 日
Use the ismember function after using the cell2mat function.
I am not certain what references you want, so it may be necessary to reverse the order of the arguments in the ismember call here —
LD = load('workspace_cell_value.mat');
vehicule2021bis2 = LD.vehicule2021bis2
vehicule2021bis2 = 9×18 table
Num_Acc num_veh id_vehicule catv grav an_nais v1 v2 circ nbv vosp prof plan infra situ vma catr voie ______________ _______ ___________ ____ ____ _______ __ _______ ____ ___ ____ ____ ____ _____ ____ ___ ____ __________ {[2.0210e+11]} {'B01'} {[201764]} 1 3 2000 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201765]} 7 1 1978 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201762]} 7 4 1983 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'B01'} {[201763]} 7 3 1993 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201761]} 7 3 1959 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201758]} 7 1 2000 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'D01'} {[201759]} 60 2 2014 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201754]} 7 4 1997 -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'Z01'} {[201755]} 7 -1 NaN -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell}
lieux2021bis3 = LD.lieux2021bis3
lieux2021bis3 = 9×19 table
Num_Acc id_vehicule catr voie v1 v2 circ nbv vosp prof pr pr1 plan lartpc larrout surf infra situ vma ______________ ___________ ____ ____________ __ ____________ ____ ___ ____ ____ __ ___ ____ ____________ _______ ____ _____ ____ ___ {[2.0210e+11]} {[201764]} 2 {'113' } 0 {'N/A' } 3 3 3 1 -1 -1 2 {0×0 char } -1 1 0 1 80 {[2.0210e+11]} {[201765]} 3 {'10' } -1 {'N/A' } 2 2 0 1 -1 -1 1 {0×0 char } 4 1 0 8 80 {[2.0210e+11]} {[201762]} 3 {'23' } -1 {'N/A' } 2 2 0 1 4 900 1 {0×0 char } -1 1 0 1 50 {[2.0210e+11]} {[201763]} 1 {'A64' } -1 {'N/A' } 3 4 0 1 99 300 1 {0×0 char } -1 1 0 3 130 {[2.0210e+11]} {[201761]} 3 {'43' } -1 {'N/A' } 2 2 0 2 -1 -1 1 {0×0 char } -1 1 0 3 80 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0
% cell2mat(vehicule2021bis2{:,1})
% cell2mat(vehicule2021bis2{:,3})
% cell2mat(lieux2021bis3{:,1})
Lv1 = cellfun(@(x)~isempty(x),lieux2021bis3{:,2})
Lv1 = 9×1 logical array
1 1 1 1 1 0 0 0 0
cell2mat(lieux2021bis3{Lv1,2})
ans = 5×1
201764 201765 201762 201763 201761
Wanted_1a = ismember(cell2mat(vehicule2021bis2.Num_Acc), cell2mat(lieux2021bis3.Num_Acc)) % Single Variable
Wanted_1a = 9×1 logical array
1 1 0 0 0 0 0 0 0
Wanted_1b = ismember(cell2mat(vehicule2021bis2{Lv1,[1 3]}), cell2mat(lieux2021bis3{Lv1,[1 2]}), 'rows') % Combined Variables
Wanted_1b = 5×1 logical array
1 0 0 0 0
Wanted_1 = find(Wanted_1a)
Wanted_1 = 2×1
1 2
Wanted_2 = ismember(cell2mat(lieux2021bis3.Num_Acc), cell2mat(vehicule2021bis2.Num_Acc))
Wanted_2 = 5×1 logical array
1 0 0 0 0
% vehicule2021bis2.catr(Wanted_2)=lieux2021bis3.catr(Wanted_2)
% vehicule2021bis2.voie(Wanted_2)=lieux2021bis3.voie(Wanted_2)
Wanted_2 = find(Wanted_2)
Wanted_2 = 1
These return logical indices. To get numerical indices from them use the find function:
I am not certain where to go on the rest of this.
.
  7 件のコメント
Greg LANGE
Greg LANGE 2023 年 4 月 24 日
ok understood
%init
LD = load('workspace_cell_value.mat');
vehicule2021bis2 = LD.vehicule2021bis2
vehicule2021bis2 = 9×18 table
Num_Acc num_veh id_vehicule catv grav an_nais v1 v2 circ nbv vosp prof plan infra situ vma catr voie ______________ _______ ___________ ____ ____ _______ __ _______ ____ ___ ____ ____ ____ _____ ____ ___ ____ __________ {[2.0210e+11]} {'B01'} {[201764]} 1 3 2000 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201765]} 7 1 1978 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201762]} 7 4 1983 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'B01'} {[201763]} 7 3 1993 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201761]} 7 3 1959 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201758]} 7 1 2000 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'D01'} {[201759]} 60 2 2014 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201754]} 7 4 1997 -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'Z01'} {[201755]} 7 -1 NaN -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell}
lieux2021bis3 = LD.lieux2021bis3
lieux2021bis3 = 9×19 table
Num_Acc id_vehicule catr voie v1 v2 circ nbv vosp prof pr pr1 plan lartpc larrout surf infra situ vma ______________ ___________ ____ ____________ __ ____________ ____ ___ ____ ____ __ ___ ____ ____________ _______ ____ _____ ____ ___ {[2.0210e+11]} {[201764]} 2 {'113' } 0 {'N/A' } 3 3 3 1 -1 -1 2 {0×0 char } -1 1 0 1 80 {[2.0210e+11]} {[201765]} 3 {'10' } -1 {'N/A' } 2 2 0 1 -1 -1 1 {0×0 char } 4 1 0 8 80 {[2.0210e+11]} {[201762]} 3 {'23' } -1 {'N/A' } 2 2 0 1 4 900 1 {0×0 char } -1 1 0 1 50 {[2.0210e+11]} {[201763]} 1 {'A64' } -1 {'N/A' } 3 4 0 1 99 300 1 {0×0 char } -1 1 0 3 130 {[2.0210e+11]} {[201761]} 3 {'43' } -1 {'N/A' } 2 2 0 2 -1 -1 1 {0×0 char } -1 1 0 3 80 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0
% request
Wanted_1a = ismember( cell2mat(lieux2021bis3.Num_Acc),cell2mat(vehicule2021bis2.Num_Acc(4))) % Single Variable
Wanted_1a = 5×1 logical array
0 0 0 0 0
Result2 = lieux2021bis3(Wanted_1a,:)
Result2 = 0×19 empty table
Then how to access a specific info ?
what is wrong ?
vehicule2021bis2.circ(4)=lieux2021bis3{Result2,7}
Error using {}
A table row subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string array, a cell array of character vectors, or a pattern scalar.
Star Strider
Star Strider 2023 年 4 月 24 日
LD = load('workspace_cell_value.mat');
vehicule2021bis2 = LD.vehicule2021bis2
vehicule2021bis2 = 9×18 table
Num_Acc num_veh id_vehicule catv grav an_nais v1 v2 circ nbv vosp prof plan infra situ vma catr voie ______________ _______ ___________ ____ ____ _______ __ _______ ____ ___ ____ ____ ____ _____ ____ ___ ____ __________ {[2.0210e+11]} {'B01'} {[201764]} 1 3 2000 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201765]} 7 1 1978 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201762]} 7 4 1983 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'B01'} {[201763]} 7 3 1993 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201761]} 7 3 1959 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201758]} 7 1 2000 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'D01'} {[201759]} 60 2 2014 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201754]} 7 4 1997 -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'Z01'} {[201755]} 7 -1 NaN -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell}
lieux2021bis3 = LD.lieux2021bis3
lieux2021bis3 = 9×19 table
Num_Acc id_vehicule catr voie v1 v2 circ nbv vosp prof pr pr1 plan lartpc larrout surf infra situ vma ______________ ___________ ____ ____________ __ ____________ ____ ___ ____ ____ __ ___ ____ ____________ _______ ____ _____ ____ ___ {[2.0210e+11]} {[201764]} 2 {'113' } 0 {'N/A' } 3 3 3 1 -1 -1 2 {0×0 char } -1 1 0 1 80 {[2.0210e+11]} {[201765]} 3 {'10' } -1 {'N/A' } 2 2 0 1 -1 -1 1 {0×0 char } 4 1 0 8 80 {[2.0210e+11]} {[201762]} 3 {'23' } -1 {'N/A' } 2 2 0 1 4 900 1 {0×0 char } -1 1 0 1 50 {[2.0210e+11]} {[201763]} 1 {'A64' } -1 {'N/A' } 3 4 0 1 99 300 1 {0×0 char } -1 1 0 3 130 {[2.0210e+11]} {[201761]} 3 {'43' } -1 {'N/A' } 2 2 0 2 -1 -1 1 {0×0 char } -1 1 0 3 80 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0 {0×0 double } {0×0 cell} 0 {0×0 double} 0 {0×0 double} 0 0 0 0 0 0 0 {0×0 double} 0 0 0 0 0
Wanted_1a = ismember(cell2mat(vehicule2021bis2.Num_Acc), cell2mat(lieux2021bis3.Num_Acc)); % Single Variable
Result = vehicule2021bis2(Wanted_1a,:)
Result = 2×18 table
Num_Acc num_veh id_vehicule catv grav an_nais v1 v2 circ nbv vosp prof plan infra situ vma catr voie ______________ _______ ___________ ____ ____ _______ __ _______ ____ ___ ____ ____ ____ _____ ____ ___ ____ __________ {[2.0210e+11]} {'B01'} {[201764]} 1 3 2000 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} {[2.0210e+11]} {'A01'} {[201765]} 7 1 1978 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell}
format long
vehic_Num_Acc = cell2mat(lieux2021bis3.Num_Acc)
vehic_Num_Acc = 5×1
1.0e+11 * 2.021000000010000 2.021000231900000 2.021000231910000 2.021000231920000 2.021000231930000
lieux_Num_Acc = cell2mat(lieux2021bis3.Num_Acc)
lieux_Num_Acc = 5×1
1.0e+11 * 2.021000000010000 2.021000231900000 2.021000231910000 2.021000231920000 2.021000231930000
Wanted_2 = ismember(cell2mat(lieux2021bis3.Num_Acc), cell2mat(vehicule2021bis2.Num_Acc)) % Are Any Elements Of vehicule2021bis2.Num_Acc' Found In 'lieux2021bis3.Num_Acc'?
Wanted_2 = 5×1 logical array
1 0 0 0 0
Only 1, and that is:
Result = lieux2021bis3(Wanted_2,:)
Result = 1×19 table
Num_Acc id_vehicule catr voie v1 v2 circ nbv vosp prof pr pr1 plan lartpc larrout surf infra situ vma _________________________ ___________ ____ _______ __ _______ ____ ___ ____ ____ __ ___ ____ __________ _______ ____ _____ ____ ___ {[2.021000000010000e+11]} {[201764]} 2 {'113'} 0 {'N/A'} 3 3 3 1 -1 -1 2 {0×0 char} -1 1 0 1 80
So, nothing is wrong. It is simply that only the first element of ‘lieux2021bis3.Num_Acc’ matches any elemnts of ‘vehicule2021bis2.Num_Acc’ and specifically:
Check1 = cell2mat(lieux2021bis3.Num_Acc) - cell2mat(vehicule2021bis2.Num_Acc).'
Check1 = 5×9
0 0 -1 -1 -2 -3 -3 -4 -4 23189 23189 23188 23188 23187 23186 23186 23185 23185 23190 23190 23189 23189 23188 23187 23187 23186 23186 23191 23191 23190 23190 23189 23188 23188 23187 23187 23192 23192 23191 23191 23190 23189 23189 23188 23188
Check2 = - cell2mat(vehicule2021bis2.Num_Acc(4)) - cell2mat(lieux2021bis3.Num_Acc)
Check2 = 5×1
1.0e+11 * -4.042000000030000 -4.042000231920000 -4.042000231930000 -4.042000231940000 -4.042000231950000
So there is only a match between the first 2 elements of ‘vehicule2021bis2.Num_Acc’ and ‘lieux2021bis3.Num_Acc’ and none of them match ‘vehicule2021bis2.Num_Acc(4)’.
That is simply how comparisons work.
.

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

その他の回答 (1 件)

Stephen23
Stephen23 2023 年 4 月 23 日
編集済み: Stephen23 2023 年 4 月 23 日
Forget about loops and FIND and ISMEMBER and other fiddling around, you should be using OUTERJOIN command. If your data are nice and tidy, then one single command is all you need. The OUTERJOIN command will be fast.
But because your data are messy (e.g. scalar/empty numeric in cell arrays), you need to tidy up the data first. For example, convert the cell array of numeric to actual numeric data, and then get rid of the missing data rows (even better: do this when you import the data).
format long G
S = load('workspace_cell_value.mat');
L = S.lieux2021bis3;
V = S.vehicule2021bis2;
L = rmmissing(convertvars(L,{'Num_Acc','id_vehicule'},@mydouble))
L = 5×19 table
Num_Acc id_vehicule catr voie v1 v2 circ nbv vosp prof pr pr1 plan lartpc larrout surf infra situ vma ____________ ___________ ____ _______ __ _______ ____ ___ ____ ____ __ ___ ____ __________ _______ ____ _____ ____ ___ 202100000001 201764 2 {'113'} 0 {'N/A'} 3 3 3 1 -1 -1 2 {0×0 char} -1 1 0 1 80 202100023190 201765 3 {'10' } -1 {'N/A'} 2 2 0 1 -1 -1 1 {0×0 char} 4 1 0 8 80 202100023191 201762 3 {'23' } -1 {'N/A'} 2 2 0 1 4 900 1 {0×0 char} -1 1 0 1 50 202100023192 201763 1 {'A64'} -1 {'N/A'} 3 4 0 1 99 300 1 {0×0 char} -1 1 0 3 130 202100023193 201761 3 {'43' } -1 {'N/A'} 2 2 0 2 -1 -1 1 {0×0 char} -1 1 0 3 80
V = rmmissing(convertvars(V,{'Num_Acc','id_vehicule'},@mydouble))
V = 8×18 table
Num_Acc num_veh id_vehicule catv grav an_nais v1 v2 circ nbv vosp prof plan infra situ vma catr voie ____________ _______ ___________ ____ ____ _______ __ _______ ____ ___ ____ ____ ____ _____ ____ ___ ____ __________ 202100000001 {'B01'} 201764 1 3 2000 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000001 {'A01'} 201765 7 1 1978 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000002 {'A01'} 201762 7 4 1983 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000002 {'B01'} 201763 7 3 1993 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000003 {'A01'} 201761 7 3 1959 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000004 {'A01'} 201758 7 1 2000 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000004 {'D01'} 201759 60 2 2014 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 202100000005 {'A01'} 201754 7 4 1997 -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell}
W = outerjoin(V,L, 'keys','Num_Acc', 'RightVariables',{'catr','voie'}, 'Type','left')
W = 8×20 table
Num_Acc num_veh id_vehicule catv grav an_nais v1 v2 circ nbv vosp prof plan infra situ vma catr_V voie_V catr_L voie_L ____________ _______ ___________ ____ ____ _______ __ _______ ____ ___ ____ ____ ____ _____ ____ ___ ______ __________ ______ __________ 202100000001 {'B01'} 201764 1 3 2000 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 2 {'113' } 202100000001 {'A01'} 201765 7 1 1978 -1 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} 2 {'113' } 202100000002 {'A01'} 201762 7 4 1983 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} NaN {0×0 char} 202100000002 {'B01'} 201763 7 3 1993 0 {'E' } 0 0 0 0 0 0 0 0 0 {0×0 cell} NaN {0×0 char} 202100000003 {'A01'} 201761 7 3 1959 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} NaN {0×0 char} 202100000004 {'A01'} 201758 7 1 2000 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} NaN {0×0 char} 202100000004 {'D01'} 201759 60 2 2014 0 {'N/A'} 0 0 0 0 0 0 0 0 0 {0×0 cell} NaN {0×0 char} 202100000005 {'A01'} 201754 7 4 1997 -1 {'N/A'} 0 0 -1 0 0 0 0 0 0 {0×0 cell} NaN {0×0 char}
function out = mydouble(inp)
out = nan(size(inp));
idx = cellfun(@isscalar,inp);
out(idx) = [inp{idx}];
end
  2 件のコメント
Greg LANGE
Greg LANGE 2023 年 4 月 23 日
thank you for your feed back, next time i will not forget to arease missing info.
Thank you for the instruction to convert propely the colonn "Num_Acc".
L = rmmissing(convertvars(L,{'Num_Acc','id_vehicule'},@mydouble))
---
I inderstand that you match both tables with the same "Num_Acc"
W = outerjoin(V,L, 'keys','Num_Acc', 'RightVariables',{'catr','voie'}, 'Type','left')
----
what the purpose of the following code ? (I don't understand it)
function out = mydouble(inp)
out = nan(size(inp));
idx = cellfun(@isscalar,inp);
out(idx) = [inp{idx}];
end
Stephen23
Stephen23 2023 年 4 月 23 日
編集済み: Stephen23 2023 年 4 月 23 日
"what the purpose of the following code ? (I don't understand it)"
It helps convert the cell array of scalar/empty numerics into a simple numeric vector: it creates a NaN array exactly the same size as the cell array and copies the scalar data into it. The function is used as an input to CONVERTVARS.
Note that OUTERJOIN will likely be much faster than anything else you try.

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

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by