Clear Filters
Clear Filters

Error while creating a table from cell

4 views (last 30 days)
I have cell containing tables with variables Frequnacy and Mode values, Now i want to create a table where each column represent frequancy and a raw has values of mode for all 48 cells.
something like this.
% Extract frequency values from the first table of Mode_shape
freq_values = Mode_shape{1}.freq;
% Preallocate the output cell array
output_cell = cell(size(freq_values));
% Loop over the frequency values and extract the corresponding Mode values
for i = 1:length(freq_values)
% Find the index of the table that matches the current frequency value
freq_index = find([Mode_shape{:}].freq == freq_values(i), 1);
% Extract the mode values from the matching table
mode_table = Mode_shape{freq_index}.mode;
% Assign the mode table to the output cell array, using the frequency value as the table name
output_cell{i} = array2table(mode_table, 'VariableNames', {'Mode'}, 'RowNames', {'Node 1', 'Node 2', 'Node 3'});
output_cell{i}.Properties.VariableUnits{'Mode'} = 'm';
output_cell{i}.Properties.Description = sprintf('Mode shape for frequency %.2f Hz', freq_values(i));
end

Accepted Answer

Star Strider
Star Strider on 11 Apr 2023
Perhaps this —
LD = load('Mode_shape.mat')
LD = struct with fields:
Mode_shape: {1×48 cell} data_cell: {1×48 cell} output_cell: {1×48 cell}
Mode_shape = (LD.Mode_shape);
freq = Mode_shape{1}.freq;
mode = cellfun(@(x)x.mode, Mode_shape, 'Unif',0);
VN = compose('%g',freq);
Mode_table = array2table(cell2mat(mode).', 'VariableNames',VN)
Mode_table = 48×43 table
5 7.5 13.75 18.75 22.5 27.5 32.5 36.25 42.5 45 48.75 51.25 56.25 60 62.5 66.25 68.75 72.5 82.5 90 93.75 100 102.5 108.75 113.75 116.25 120 125 127.5 130 133.75 136.25 140 146.25 153.75 157.5 162.5 170 181.25 185 190 192.5 196.25 ___________ ___________ ___________ ___________ ___________ __________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ __________ __________ ___________ ___________ ___________ __________ ___________ ___________ ___________ ___________ __________ __________ __________ __________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ ___________ -0.00022306 -0.0016559 8.7761e-05 0.00015143 -0.00037047 0.0012073 -6.5725e-05 -0.00066836 -0.00032238 -0.00023063 0.00019979 -0.00033541 0.00012908 -0.00011987 0.0030057 0.00070089 -0.0011947 0.0046722 -0.00073056 -0.000445 0.0008882 -0.0065965 -0.00013824 0.00013091 -0.00015059 0.00068167 0.00030093 0.00067519 -0.012468 0.00075823 0.00020806 0.00020595 0.0001513 -8.4978e-05 5.4239e-05 0.00016389 -0.00030113 0.00015752 0.00088649 0.0002888 0.00029925 0.00035816 0.00035556 0.0010585 -0.00045931 -0.00034242 -0.00020505 -0.00025865 0.00010493 -0.00012892 0.00029278 0.00024352 0.00020516 -0.0022649 -0.0022255 0.00014703 -0.00024902 -0.00090294 0.00035851 0.0007015 0.0055156 0.00052696 -0.00048931 -0.00011389 -0.0050822 9.9918e-05 -0.00010489 -0.00019023 -0.00025328 0.00036361 0.0006332 0.0011313 0.00035317 0.0001357 0.00023074 -0.00020601 0.00022568 8.46e-05 -0.00017713 0.00020139 -0.00029048 -0.00053927 -6.2872e-05 -0.00039034 -0.00039947 0.00046579 0.00073099 0.00032569 -0.00051451 0.0004379 -0.00049416 0.00065033 -0.00016813 0.00056885 0.00042667 0.00041487 -0.00059831 -0.0011214 0.00018872 -0.00095127 -0.0020558 0.0003641 0.00093098 0.0068808 0.00063007 -0.00038808 -0.00044659 0.010847 -0.00029491 -0.00013172 -0.00024745 -0.00031301 0.00046444 0.0007924 0.0015036 0.00043493 0.00013969 0.00019531 0.00026906 0.00030716 0.00011169 -0.00024536 -0.00024983 -0.00035367 -0.00067386 -9.2256e-06 -0.00047333 -0.00043334 0.00054685 0.0015792 0.00041172 -0.00093045 0.00079979 -0.00083817 -0.0010547 -0.00021891 0.0010594 0.00093066 0.00094482 0.0025914 -0.0010534 0.0005142 -0.002352 -0.0034111 0.00038496 0.0013851 0.0079079 0.0012036 -0.00058883 0.00093542 -0.016487 -0.00014497 0.00030468 -0.00020027 -0.00031949 0.00058314 0.00090599 0.0019296 0.0011887 -0.00026586 -0.00024412 -0.0007468 0.00049927 3.1293e-05 -0.00023005 -0.00020065 -0.00030402 -0.00078892 -0.00016859 0.00042184 -0.00028381 0.00047687 0.049654 0.014588 -0.024494 0.021895 0.026002 -0.029692 -0.011238 0.02852 0.024516 0.018375 0.036053 -0.039409 0.033256 -0.039734 0.051033 0.0022463 0.014443 -0.10791 0.022548 -0.032066 0.012914 0.042066 -0.0013377 0.0048018 -0.0055327 -0.0021 0.0017853 -0.015579 -0.022238 -0.013003 -0.011262 -0.014042 -0.014085 0.011083 0.0021498 -0.001693 -0.0030843 -0.0076203 0.010766 0.014158 -0.0034755 -0.011024 -0.0060864 -0.0016825 -0.0039596 -0.0031245 -0.00043814 0.00072298 0.0025337 -0.0098518 -0.0041742 -0.0073536 0.0095366 -0.012729 0.016217 -0.026781 -0.097062 0.19984 -0.011722 -0.034372 -0.4591 -0.020268 -0.048272 -0.024357 -0.016068 -0.012065 0.0080391 -0.0074696 -0.011387 -0.020817 -0.0566 -0.11111 -0.053676 -0.026422 -0.025208 -0.023551 0.0011385 -0.0017844 0.0054547 -0.0098018 -0.018485 0.044829 0.031039 0.017287 -0.021324 -0.024105 0.01606 0.14479 -0.0081702 -0.015032 0.041272 -0.096148 -0.011013 0.046411 -0.026144 0.012076 -0.011502 0.033057 -0.028035 0.052613 0.67397 0.025084 0.063906 -0.51971 0.04996 -0.080176 -0.062208 0.020247 0.0064773 -0.0089061 0.011329 -0.047814 -0.015016 -0.092564 2.7413 -0.13309 -0.047723 -0.029918 0.017482 0.019349 -0.014982 -0.011023 0.0066894 -0.0035687 -0.18135 -0.021132 -0.0085878 -0.0027621 -0.0014435 0.0021447 -0.0045491 -7.043e-05 -0.00088418 0.0016698 0.0036982 -0.017088 -0.0034012 0.0095038 -0.012046 -0.016785 0.020842 -0.037072 0.075055 0.34792 -0.013679 -0.041446 -0.66534 -0.029598 -0.071883 -0.037429 -0.027102 -0.021051 -0.0094996 -0.0034545 -0.0037658 -0.016968 -0.068227 -0.14344 -0.096095 -0.048334 -0.042912 -0.030694 0.016462 -0.01333 -0.0090746 -0.0052538 -0.0040158 0.040318 0.071052 -0.0049818 -0.0012494 -0.0025502 0.00062942 0.021186 -0.0075448 -0.00049322 0.0028289 0.0059789 -0.018503 0.0041889 -0.0116 0.012399 0.016807 0.018877 -0.039794 0.09137 0.86159 0.060013 0.020822 -0.61524 -0.039953 -0.10424 -0.041058 -0.029163 -0.022595 0.024088 0.0045453 -0.0058237 -0.017845 -0.12464 3.0464 -0.12842 -0.054142 -0.042993 -0.04794 0.021813 -0.015475 0.012561 -0.016895 0.00020545 -0.24706 -0.029052 -0.014875 -0.009154 -0.0048909 0.0040029 -0.0058327 -0.0016759 -0.00073156 0.0017538 0.0040849 -0.013795 0.001594 0.0040187 -0.0050266 -0.0083904 -0.0095197 -0.019817 0.02536 0.21314 -0.010331 -0.018253 -0.31408 -0.015018 -0.041084 -0.021747 -0.024228 -0.01322 -0.0109 -0.0082001 -0.0043215 -0.0026221 -0.030885 -0.073215 -0.062776 -0.033568 -0.028766 0.021879 -0.016635 0.015227 -0.013405 -0.011529 0.008504 0.015412 0.053276 0.017246 -0.016954 -0.013869 0.0001297 9.6712e-05 6.889e-05 -4.5405e-05 -4.6137e-05 2.9893e-05 0.00015408 5.4078e-05 -0.00018661 8.925e-05 -0.0001851 -0.00037772 -0.00022679 0.00039548 -0.0028305 9.7705e-05 0.0002869 0.0039924 0.00028217 0.00057842 -0.00037434 0.0062474 0.00074632 0.00014178 -0.00010867 -4.5402e-05 5.5657e-05 0.00036287 0.00089044 0.00071485 0.00040177 0.00037901 -0.00023861 -0.00027746 0.00019773 -0.00018939 -0.00017293 -0.00010665 -0.00016973 -0.00060886 -0.00022983 -0.00014129 0.00019134 0.0032726 -0.00359 0.00071411 -0.00064172 -0.0011413 0.0012236 -0.0095464 0.00077788 -0.0026177 -0.0035969 -0.006593 -0.0067027 -0.013044 0.01477 0.14526 -0.0070539 -0.01255 -0.20578 -0.010377 -0.032306 -0.017334 0.01942 -0.01199 0.0093088 -0.0042216 -0.0028233 -0.0010194 -0.020731 -0.048856 -0.031819 -0.021031 -0.019443 -0.018659 -0.011498 0.010459 -0.009546 -0.0087731 -0.0071331 0.0079838 0.035258 -0.013386 -0.012278 0.011152 0.0056292 0.074674 0.011037 0.004814 0.0034389 -0.026014 0.082408 0.023466 -0.0076986 -0.009262 -0.005851 -0.0088993 -0.010589 0.01939 -0.074393 -0.0088835 0.0090311 -0.36985 -0.025436 -0.079058 -0.046376 0.055077 0.065663 0.20845 -0.051098 -0.34384 0.63685 0.26339 0.7284 -0.16726 0.079314 -0.074224 -0.21373 0.018532 -0.029065 0.033475 -0.03677 -0.086267 0.43882 -0.084361 -0.052197 -0.041538 -0.032404 0.0038941 0.065604 -0.0089704 0.0056951 0.0084221 -0.026489 0.083795 0.016098 -0.003853 -0.0029816 -0.003797 -0.0010269 0.0082151 -0.032731 -0.40723 -0.044616 -0.02084 -0.0039305 0.012758 0.052522 0.024987 0.031371 -0.03412 -0.14462 0.0067964 -0.017267 -0.017616 0.026847 -1.9074 -0.24034 0.032976 0.010718 -0.12205 0.0052314 -0.0094538 0.01378 -0.027159 -0.074479 0.42095 -0.10222 -0.069364 -0.057824 -0.04787 0.0030391 -0.019903 -0.0029086 0.0070488 0.0096886 -0.022375 -0.12382 0.015516 0.00089288 0.0038582 0.012714 0.016497 0.032962 -0.038188 -0.52942 0.033372 0.032976 0.53613 0.048457 0.20114 -0.16711 0.21934 0.52231 -0.065367 -0.027414 -0.077638 -0.27113 -0.33399 -0.17011 -0.10137 -0.074709 -0.070932 0.039059 -0.035192 -0.027706 -0.021493 -0.013789 -0.011271 -0.26063 0.10475 -0.063921 -0.055963 -0.051732 8.017e-05 -0.0011781 0.00032811 -0.00010305 -2.0462e-05 0.00018385 -0.0020468 0.00046982 -9.4929e-05 0.00017416 -0.002814 -0.0018619 0.00053104 -0.0012077 -0.0096924 -0.00083249 0.00018123 0.0095819 0.00075802 0.0029723 0.0016215 0.0066568 -0.0030002 -0.0042755 -0.00036214 0.003495 -0.0048329 -0.010373 0.0043951 0.0023154 -0.001351 -0.0012171 -0.0017774 0.00057074 -0.00042307 0.00036126 -0.00029641 0.00011822 -0.010197 -0.0011368 -0.0007683 -0.00063554 -0.00052968
.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!