how to read a table and multiply its elements with eachother and store it in another table

3 vues (au cours des 30 derniers jours)
i have a table of dimension 152*3, I want to multiply all the elments in row 1 ie: row (1,1)*(1,2)*(1,3) and store its value in another table.
this should be done for each rows untill the last and each values should be stored and viewed in another table

Réponses (2)

Davide Masiello
Davide Masiello le 6 Avr 2022
Example
%% Creating an example table
T = array2table(rand(152,3));
T.Properties.VariableNames = {'A','B','C'};
disp(T)
A B C ________ _________ _________ 0.42378 0.13393 0.22799 0.082036 0.41103 0.47176 0.75376 0.92698 0.35121 0.76344 0.59448 0.15683 0.6067 0.82957 0.65986 0.13342 0.45348 0.40703 0.6811 0.064675 0.4763 0.39749 0.42151 0.49343 0.25655 0.85027 0.75015 0.2818 0.17302 0.22054 0.43358 0.30905 0.094299 0.067233 0.42883 0.31584 0.59127 0.47814 0.64779 0.21798 0.21966 0.81706 0.24648 0.16125 0.71757 0.47834 0.8578 0.90381 0.33964 0.32478 0.6592 0.58716 0.72589 0.63555 0.2079 0.94555 0.11394 0.23356 0.47505 0.62317 0.38324 0.63074 0.96923 0.029543 0.50752 0.66974 0.47596 0.68114 0.10123 0.51391 0.64901 0.5895 0.62073 0.12588 0.42946 0.14064 0.8107 0.55923 0.55861 0.20972 0.026246 0.88244 0.85151 0.67231 0.24386 0.0091537 0.81313 0.24565 0.40811 0.17537 0.82064 0.70851 0.028089 0.13386 0.50029 0.7247 0.023885 0.67824 0.11584 0.049607 0.67578 0.90859 0.67972 0.53723 0.87945 0.70288 0.24487 0.54332 0.10835 0.11454 0.03875 0.586 0.8897 0.48103 0.19033 0.28499 0.43309 0.16974 0.84623 0.8983 0.25022 0.38247 0.49594 0.14369 0.81799 0.49193 0.017027 0.25476 0.9341 0.69411 0.73299 0.91914 0.63633 0.47565 0.94537 0.26791 0.21803 0.67819 0.59145 0.45666 0.23451 0.89969 0.23141 0.91394 0.30595 0.79774 0.54422 0.82913 0.20912 0.3579 0.56273 0.080806 0.60201 0.56198 0.2252 0.013156 0.98202 0.21236 0.67949 0.30891 0.78289 0.93988 0.92229 0.92271 0.84322 0.96672 0.47785 0.45762 0.84022 0.10221 0.68097 0.030949 0.76589 0.77341 0.85085 0.49493 0.91834 0.67863 0.26774 0.45319 0.91824 0.38266 0.58674 0.11981 0.34745 0.3926 0.45039 0.2838 0.065324 0.77591 0.67981 0.37745 0.96183 0.76159 0.98151 0.093357 0.079286 0.80662 0.010607 0.79386 0.62656 0.85305 0.74432 0.57746 0.28166 0.29303 0.31683 0.06148 0.55658 0.52646 0.20803 0.39411 0.26235 0.37679 0.16947 0.16664 0.40762 0.69195 0.94204 0.86755 0.62125 0.15093 0.6197 0.84974 0.67479 0.15956 0.1419 0.069695 0.94574 0.14687 0.3861 0.010654 0.41531 0.95663 0.090716 0.01221 0.38156 0.38419 0.40451 0.96042 0.034027 0.36074 0.36304 0.7896 0.31645 0.44171 0.95109 0.036508 0.011216 0.68574 0.89948 0.24477 0.81051 0.44184 0.06977 0.21326 0.98712 0.89869 0.47508 0.66351 0.025417 0.50793 0.35838 0.21829 0.63055 0.80763 0.81413 0.91354 0.96246 0.28164 0.81592 0.48461 0.45038 0.72469 0.94251 0.36319 0.89172 0.096547 0.72459 0.46539 0.33833 0.85381 0.25951 0.21369 0.10845 0.74297 0.96254 0.48982 0.12529 0.88964 0.55652 0.45328 0.59957 0.49526 0.25019 0.37341 0.85707 0.80745 0.56399 0.17451 0.57691 0.72659 0.40315 0.68526 0.70135 0.69743 0.71913 0.94173 0.8324 0.57787 0.26485 0.12257 0.11568 0.28255 0.86964 0.50212 0.37506 0.0041642 0.67394 0.2847 0.67101 0.81317 0.12404 0.33385 0.5364 0.74537 0.60136 0.11061 0.72833 0.46459 0.10321 0.43555 0.90648 0.93456 0.82242 0.51391 0.65652 0.030484 0.69796 0.80008 0.633 0.13769 0.027733 0.32003 0.96669 0.48346 0.80731 0.47872 0.42179 0.12564 0.92077 0.69997 0.43716 0.06826 0.62567 0.78622 0.58397 0.55886 0.9579 0.91042 0.23519 0.15555 0.014037 0.97677 0.57281 0.83796 0.84611 0.68231 0.99345 0.2854 0.67092 0.68178 0.28414 0.15534 0.52458 0.67874 0.4807 0.87333 0.47587 0.044565 0.7615 0.15419 0.46918 0.54308 0.49933 0.91122 0.31492 0.44477 0.34637 0.26137 0.19595 0.69232 0.92582 0.58582 0.12117 0.39024 0.71311 0.65721 0.85462 0.09565 0.61922 0.51532 0.96703 0.22528 0.19192 0.21275 0.029376 0.2551 0.031148 0.75886 0.52969 0.82803 0.65453 0.21013 0.70479 0.11133 0.89817 0.029264 0.18215 0.0044201 0.81203 0.059566 0.23815 0.52536 0.81921 0.47153 0.73952 0.93181 0.079821 0.52958 0.96271 0.5986 0.95124 0.86234 0.71223 0.81267 0.57192 0.77478 0.17716 0.61609 0.028296 0.040548 0.41582 0.72524 0.24942 0.58864 0.59282 0.44106 0.32027 0.59054 0.44587 0.019645 0.87156 0.14007 0.56612 0.91016
%% New table with product
T_prod = array2table(prod(T{:,:},2));
T_prod.Properties.VariableNames = {'product'};
disp(T_prod)
product __________ 0.01294 0.015907 0.2454 0.071177 0.33211 0.024626 0.020981 0.082671 0.16364 0.010752 0.012636 0.009106 0.18314 0.039121 0.02852 0.37086 0.072715 0.27088 0.022398 0.069143 0.23429 0.010042 0.032819 0.19662 0.033556 0.063763 0.0030748 0.50518 0.0018151 0.017581 0.016332 0.048534 0.0018765 0.030459 0.32114 0.093513 0.0004809 0.25079 0.023492 0.12903 0.047463 0.057822 0.0040519 0.46764 0.28614 0.039614 0.06334 0.19028 0.13283 0.062056 0.027375 0.001665 0.1417 0.2273 0.71759 0.2114 0.058478 0.018333 0.38672 0.082344 0.20617 0.016344 0.0083496 0.1991 0.71898 0.0059705 0.0052759 0.36666 0.026149 0.018014 0.021509 0.01064 0.26571 0.081347 0.35534 0.0015781 0.053631 0.0042328 0.00042264 0.14926 0.0044563 0.11037 0.00038943 0.15097 0.024986 0.18919 0.008012 0.039736 0.4146 0.24763 0.17808 0.24807 0.062382 0.13444 0.0060139 0.35029 0.062029 0.1346 0.080069 0.079471 0.16899 0.33519 0.56372 0.018759 0.028423 0.00078423 0.12875 0.033675 0.24044 0.037429 0.04075 0.39499 0.013969 0.069735 0.0085799 0.18685 0.048794 0.020887 0.28726 0.48737 0.00051353 0.46884 0.57352 0.13055 0.023154 0.28494 0.016149 0.039289 0.14329 0.040264 0.1256 0.027701 0.40053 0.030522 0.041811 0.0015943 0.01252 0.11389 0.070475 2.3562e-05 0.011519 0.20294 0.055004 0.30519 0.58424 0.36011 0.0030884 0.012228 0.087039 0.083421 0.0076343 0.072172

Stephen23
Stephen23 le 6 Avr 2022
Modifié(e) : Stephen23 le 6 Avr 2022
If all you need are numeric operations across all columns then storing the data in one numeric matrix would make your task much easier and more efficient. But if you must use a table:
T = array2table(rand(152,3), 'VariableNames',{'A','B','C'})
T = 152×3 table
A B C ________ _________ ________ 0.54535 0.98312 0.43502 0.58908 0.0013448 0.016707 0.21073 0.047291 0.45771 0.88526 0.26006 0.45427 0.23476 0.82321 0.67366 0.85761 0.96404 0.5221 0.41686 0.18252 0.96219 0.334 0.84439 0.44205 0.4472 0.78245 0.59439 0.034742 0.69014 0.75689 0.56919 0.90472 0.40937 0.97928 0.78709 0.84837 0.63946 0.40587 0.32266 0.96012 0.37461 0.27548 0.86979 0.64672 0.70659 0.73997 0.85677 0.45199
F = @(varargin)prod([varargin{:}]);
Z = rowfun(F,T)
Z = 152×1 table
Var1 __________ 0.23323 1.3235e-05 0.0045614 0.10458 0.13019 0.43166 0.073207 0.12467 0.20798 0.018148 0.21081 0.65391 0.083741 0.099082 0.39747 0.28656

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by