Extract a column from cell array containing arrays
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Share a link to this question
Hi everyone,
I'm stuck with this problem: I have a cell array 400x30 and every cell contains an array 1x3. I want to extract the first element of each array of the first column. I want to plot them, so I guess I need to put them in a separate array.
I searched similar questions in the forum, but, even if I "mixed" the answers, I couldn't solve my problem.
Could someone help me?
Thank you in advance :)
Chiara
Accepted Answer
% 400x30 cell of 1x3 random vectors:
C = reshape(num2cell(rand(400*30,3),2),400,[])
C = 400×30 cell array
{[0.4837 0.5479 0.9608]} {[0.8740 0.3447 0.0894]} {[0.1324 0.1130 0.9205]} {[0.6612 0.6216 0.5873]} {[0.4619 0.8044 0.3733]} {[0.7118 0.5678 0.3860]} {[0.2325 0.9970 0.5401]} {[0.0200 0.3322 0.0542]} {[0.4560 0.2895 0.6130]} {[0.1519 0.4753 0.5754]} {[0.8171 0.4048 0.4573]} {[0.7354 0.5425 0.5611]} {[0.3328 0.0975 0.9783]} {[0.8574 0.3883 0.5081]} {[0.8225 0.3406 0.8372]} {[0.7205 0.7736 0.3347]} {[0.0384 0.6472 0.9744]} {[0.9788 0.7953 0.0246]} {[0.9149 0.5762 0.6241]} {[0.2323 0.3532 0.7466]} {[0.2986 0.4747 0.5098]} {[0.8800 0.5503 0.5935]} {[0.0667 0.2037 0.2614]} {[0.6787 0.1557 0.9346]} {[0.1189 0.9244 0.7989]} {[0.1945 0.9929 0.5621]} {[0.7551 0.7505 0.1591]} {[0.6601 0.0280 0.2409]} {[0.0305 0.0797 0.5151]} {[0.2559 0.6368 0.8397]}
{[0.8256 0.7417 0.3556]} {[0.4592 0.0586 0.1227]} {[0.7049 0.5271 0.5945]} {[0.4509 0.5334 0.6379]} {[0.0687 0.2351 0.7441]} {[0.7839 0.9819 0.1167]} {[0.7122 0.3132 0.5442]} {[0.7732 0.0697 0.0487]} {[0.5106 0.4487 0.6065]} {[0.3814 0.9769 0.0647]} {[0.8269 0.7156 0.0518]} {[0.4651 0.3978 0.6046]} {[0.7178 0.0011 0.7014]} {[0.0601 0.9732 0.8102]} {[0.1606 0.5377 0.2816]} {[0.8022 0.8079 0.0159]} {[0.3695 0.1328 0.1443]} {[0.4676 0.0508 0.5727]} {[0.5443 0.7566 0.8503]} {[0.0107 0.5040 0.8610]} {[0.4242 0.9383 0.1115]} {[0.0932 0.0828 0.9369]} {[0.2591 0.1187 0.6178]} {[0.0037 0.5793 0.0924]} {[0.4344 0.0524 0.6553]} {[0.8503 0.4326 0.8567]} {[0.6300 0.1720 0.8717]} {[0.7369 0.1118 0.2215]} {[0.9386 0.2284 0.8319]} {[0.8376 0.6891 0.6920]}
{[0.5549 0.6056 0.4723]} {[0.4091 0.4082 0.9107]} {[0.0982 0.4066 0.0968]} {[0.7266 0.5788 0.4095]} {[0.8680 0.5753 0.0486]} {[0.0748 0.2115 0.6639]} {[0.5388 0.4559 0.9605]} {[0.3071 0.2882 0.3278]} {[0.8893 0.0140 0.7049]} {[0.1695 0.8868 0.8048]} {[0.3605 0.4364 0.7673]} {[0.6311 0.6105 0.9153]} {[0.7511 0.5228 0.6202]} {[0.4553 0.1675 0.4947]} {[0.8662 0.7652 0.1532]} {[0.1720 0.3699 0.1499]} {[0.4470 0.2022 0.3646]} {[0.7851 0.9267 0.5186]} {[0.4080 0.6358 0.0468]} {[0.4649 0.4538 0.6045]} {[0.6417 0.5620 0.1627]} {[0.4702 0.0695 0.8553]} {[0.9411 0.2386 0.1096]} {[0.0912 0.7837 0.3938]} {[0.5545 0.5201 0.4134]} {[0.3380 0.2118 0.4203]} {[0.1652 0.6318 0.0331]} {[0.2722 0.3190 0.6849]} {[0.5397 0.6789 0.1104]} {[0.5722 0.9089 0.5851]}
{[0.0788 0.8490 0.9890]} {[0.3883 0.8900 0.7185]} {[0.3312 0.8645 0.0857]} {[0.6314 0.8286 0.2238]} {[0.8679 0.7740 0.7044]} {[0.9967 0.1816 0.0508]} {[0.9261 0.5401 0.9620]} {[0.5456 0.8579 0.8158]} {[0.1639 0.0836 0.0100]} {[0.2139 0.8480 0.6319]} {[0.0530 0.5922 0.0564]} {[0.5565 0.2253 0.8306]} {[0.3360 0.5843 0.8877]} {[0.5524 0.4638 0.4107]} {[0.8465 0.6650 0.6172]} {[0.7286 0.2835 0.5075]} {[0.4273 0.1658 0.6900]} {[0.2620 0.5132 0.7666]} {[0.8590 0.8026 0.6721]} {[0.4911 0.7929 0.8805]} {[0.9668 0.7417 0.9387]} {[0.1840 0.0479 0.3634]} {[0.5850 0.8498 0.9513]} {[0.1206 0.1088 0.8556]} {[0.5714 0.3601 0.5031]} {[0.6423 0.1588 0.3492]} {[0.9187 0.9525 0.3367]} {[0.4693 0.2796 0.9464]} {[0.9607 0.3978 0.2565]} {[0.3223 0.1618 0.9614]}
{[0.4740 0.6440 0.9835]} {[0.7031 0.3909 0.4786]} {[0.0956 0.4327 0.5267]} {[0.7025 0.5465 0.4054]} {[0.2697 0.8395 0.5352]} {[0.6983 0.6648 0.6360]} {[0.4640 0.0288 0.7687]} {[0.7186 0.2388 0.5413]} {[0.9529 0.4493 0.3741]} {[0.1031 0.9649 0.9418]} {[0.9618 0.5125 0.1941]} {[0.5651 0.4094 0.4267]} {[0.0930 0.6638 0.8684]} {[0.8350 0.1093 0.0787]} {[0.2929 0.1909 0.5675]} {[0.0082 0.5910 0.5860]} {[0.8387 0.8104 0.6301]} {[0.2495 0.0242 0.8045]} {[0.7764 0.6953 0.5042]} {[0.0752 0.5737 0.8014]} {[0.3261 0.5973 0.3594]} {[0.6248 0.5492 0.5841]} {[0.9437 0.9742 0.8127]} {[0.5454 0.4878 0.5969]} {[0.9168 0.5589 0.8724]} {[0.2736 0.4871 0.7337]} {[0.4397 0.7899 0.6821]} {[0.7255 0.9487 0.0774]} {[0.8021 0.7963 0.4184]} {[0.4656 0.1897 0.0508]}
{[0.5338 0.0416 0.0283]} {[0.7526 0.9254 0.7262]} {[0.5498 0.1496 0.3798]} {[0.4832 0.4456 0.3445]} {[0.8979 0.8813 0.9888]} {[0.8777 0.6003 0.7246]} {[0.0600 0.6236 0.8887]} {[0.7067 0.4441 0.4416]} {[0.0356 0.0168 0.3908]} {[0.8490 0.4467 0.6501]} {[0.9712 0.0299 0.8119]} {[0.0492 0.6419 0.4851]} {[0.2202 0.6323 0.1903]} {[0.3548 0.7279 0.4414]} {[0.0882 0.1935 0.3455]} {[0.4211 0.9720 0.7946]} {[0.2338 0.9278 0.5619]} {[0.2085 0.1994 0.2749]} {[0.4386 0.9431 0.3582]} {[0.6316 0.2090 0.2844]} {[0.9799 0.0388 0.3862]} {[0.9853 0.1409 0.7635]} {[0.5281 0.1044 0.7337]} {[0.2062 0.0378 0.7371]} {[0.5461 0.0990 0.5748]} {[0.3105 0.7954 0.0301]} {[0.2766 0.7251 0.3443]} {[0.3531 0.1930 0.8259]} {[0.6678 0.8389 0.0738]} {[0.9592 0.6472 0.1813]}
{[0.6690 0.8798 0.8903]} {[0.4193 0.0258 0.6367]} {[0.5614 0.2985 0.4244]} {[0.0265 0.6818 0.0335]} {[0.2019 0.3967 0.6564]} {[0.6552 0.0672 0.7762]} {[0.3658 0.7051 0.1965]} {[0.4005 0.3529 0.2174]} {[0.7309 0.0466 0.8950]} {[0.8173 0.5911 0.2147]} {[0.8237 0.1622 0.6896]} {[0.1971 0.3567 0.4296]} {[0.4563 0.1769 0.4636]} {[0.3923 0.9724 0.2320]} {[0.4221 0.5069 0.8784]} {[0.4862 0.5784 0.2201]} {[0.6172 0.3137 0.8019]} {[0.5014 0.5803 0.2544]} {[0.1152 0.9983 0.8778]} {[0.8745 0.2788 0.4817]} {[0.2982 0.4889 0.7505]} {[0.1953 0.5256 0.4659]} {[0.8233 0.2660 0.2332]} {[0.2180 0.2077 0.1297]} {[0.5983 0.2302 0.1526]} {[0.2572 0.5000 0.5916]} {[0.0465 0.7738 0.9477]} {[0.8519 0.2656 0.0131]} {[0.1423 0.5800 0.4158]} {[0.4876 0.5546 0.3007]}
{[0.8101 0.0701 0.7111]} {[0.7243 0.9519 0.6616]} {[0.5799 0.4368 0.1521]} {[0.4406 0.8420 0.4003]} {[0.4264 0.4425 0.3172]} {[0.0973 0.0075 0.7492]} {[0.6620 0.6270 0.3439]} {[0.4242 0.2267 0.5790]} {[0.9587 0.3707 0.5244]} {[0.7218 0.0968 0.5104]} {[0.3534 0.4064 0.8220]} {[0.2709 0.3663 0.2996]} {[0.1132 0.7857 0.7159]} {[0.7253 0.1151 0.8383]} {[0.2636 0.4311 0.5587]} {[0.1935 0.2722 0.9825]} {[0.2115 0.9707 0.8707]} {[0.2095 0.0252 0.3365]} {[0.0884 0.3246 0.5988]} {[0.3745 0.0970 0.8368]} {[0.8799 0.6103 0.4158]} {[0.1194 0.3970 0.6666]} {[0.6464 0.2854 0.5060]} {[0.5217 0.1256 0.2598]} {[0.4975 0.4014 0.3960]} {[0.0436 0.2074 0.7811]} {[0.0452 0.2247 0.0204]} {[0.4353 0.2068 0.1280]} {[0.4962 0.1291 0.7826]} {[0.0980 0.4691 0.1509]}
{[0.3931 0.2147 0.1128]} {[0.7120 0.4916 0.6489]} {[0.9851 0.3103 0.6628]} {[0.0779 0.7665 0.8331]} {[0.6079 0.9996 0.9521]} {[0.7469 0.4178 0.3185]} {[0.6458 0.2222 0.3456]} {[0.0630 0.1153 0.8999]} {[0.0923 0.5957 0.4600]} {[0.1773 0.2163 0.0341]} {[0.1143 0.8725 0.5213]} {[0.3538 0.3945 0.0099]} {[0.9882 0.3244 0.9005]} {[0.1814 0.5831 0.6543]} {[0.3046 0.3577 0.9629]} {[0.0837 0.1988 0.2158]} {[0.6012 0.6122 0.8180]} {[0.2084 0.6530 0.1329]} {[0.4567 0.7998 0.6229]} {[0.5604 0.9585 0.7885]} {[0.1455 0.1571 0.7825]} {[0.8098 0.1124 0.6113]} {[0.4093 0.5224 0.8824]} {[0.8472 0.7005 0.4896]} {[0.3292 0.3714 0.2693]} {[0.3222 0.8306 0.9240]} {[0.9638 0.9011 0.9955]} {[0.3620 0.4603 0.0667]} {[0.9914 0.7352 0.9483]} {[0.4044 0.2173 0.2306]}
{[0.8212 0.9734 0.8406]} {[0.6847 0.9813 0.7140]} {[0.6415 0.5442 0.4869]} {[0.6561 0.1982 0.6754]} {[0.4268 0.6907 0.4854]} {[0.9211 0.0253 0.3084]} {[0.8204 0.7730 0.9064]} {[0.7044 0.4361 0.4741]} {[0.1864 0.4088 0.3198]} {[0.8216 0.6609 0.6419]} {[0.8203 0.6612 0.3059]} {[0.4255 0.9754 0.7308]} {[0.4428 0.8753 0.0076]} {[0.7608 0.6652 0.1454]} {[0.8108 0.9637 0.3491]} {[0.7484 0.9944 0.6001]} {[0.9059 0.3448 0.8140]} {[0.0598 0.5770 0.5844]} {[0.5630 0.8726 0.5904]} {[0.3571 0.1817 0.9957]} {[0.3091 0.8961 0.1120]} {[0.5101 0.0435 0.9886]} {[0.9889 0.6029 0.3432]} {[0.1225 0.9766 0.0210]} {[0.3239 0.5744 0.5497]} {[0.0960 0.1308 0.9475]} {[0.2005 0.2901 0.9302]} {[0.0221 0.7462 0.7434]} {[0.4858 0.1259 0.0204]} {[0.9786 0.9287 0.2042]}
{[0.1986 0.3884 0.4858]} {[0.4537 0.5463 0.2020]} {[0.8516 0.6805 0.1092]} {[0.9572 0.4085 0.3926]} {[0.7015 0.5496 0.8890]} {[0.6601 0.0059 0.3466]} {[0.1305 0.6630 0.1181]} {[0.8895 0.0456 0.6786]} {[0.7027 0.2057 0.9645]} {[0.3474 0.2080 0.3558]} {[0.0131 0.6426 0.3651]} {[0.8334 0.9675 0.2596]} {[0.4112 0.6319 0.1716]} {[0.0038 0.8288 0.7512]} {[0.3765 0.3935 0.1513]} {[0.2513 0.2035 0.8882]} {[0.7309 0.4445 0.0941]} {[0.1130 0.9256 0.7420]} {[0.6368 0.4931 0.2441]} {[0.8460 0.2288 0.7460]} {[0.2058 0.5896 0.8834]} {[0.8899 0.3923 0.8843]} {[0.2560 0.6733 0.8569]} {[0.0671 0.7443 0.0739]} {[0.8395 0.8269 0.9167]} {[0.5567 0.2281 0.8641]} {[0.7965 0.8122 0.7714]} {[0.2042 0.3360 0.6522]} {[0.5757 0.7484 0.9566]} {[0.3920 0.9251 0.4901]}
{[0.5529 0.5231 0.0089]} {[0.7994 0.3670 0.3805]} {[0.9418 0.0345 0.1675]} {[0.5233 0.4372 0.0052]} {[0.9316 0.3693 0.9184]} {[0.8014 0.8803 0.7272]} {[0.0718 0.0970 0.5921]} {[0.9470 0.4953 0.9295]} {[0.0674 0.0263 0.9055]} {[0.4809 0.4394 0.0436]} {[0.2569 0.5318 0.9830]} {[0.0121 0.1660 0.5878]} {[0.6232 0.8621 0.5788]} {[0.5535 0.5102 0.9460]} {[0.2813 0.5256 0.5672]} {[0.2838 0.2537 0.7169]} {[0.9680 0.3056 0.9790]} {[0.2860 0.2832 0.5920]} {[0.3797 0.2000 0.4297]} {[0.3824 0.7988 0.0196]} {[0.5667 0.4902 0.4913]} {[0.3077 0.6865 0.4992]} {[0.0929 0.4744 0.6410]} {[0.4974 0.5873 0.6082]} {[0.3050 0.8002 0.4510]} {[0.4656 0.4765 0.9013]} {[0.6435 0.0826 0.5162]} {[0.2834 0.2166 0.2668]} {[0.5962 0.2145 0.2874]} {[0.8063 0.7309 0.7852]}
{[0.2528 0.9893 0.5299]} {[0.5508 0.1951 0.3311]} {[0.3670 0.9143 0.1113]} {[0.2537 0.6860 0.0323]} {[0.3383 0.9572 0.7438]} {[0.4558 0.7856 0.1936]} {[0.9615 0.3546 0.5148]} {[0.8848 0.2885 0.2265]} {[0.1947 0.5325 0.8871]} {[0.0237 0.1796 0.3493]} {[0.6263 0.1123 0.9287]} {[0.3426 0.3882 0.1770]} {[0.9710 0.8175 0.4111]} {[0.4685 0.4824 0.6810]} {[0.6004 0.0326 0.1220]} {[0.7025 0.4850 0.8902]} {[0.2984 0.8840 0.8529]} {[0.7517 0.1536 0.8892]} {[0.6687 0.3569 0.9948]} {[0.0887 0.5132 0.3273]} {[0.5850 0.8437 0.2936]} {[0.8004 0.4721 0.3655]} {[0.2698 0.4545 0.3635]} {[0.1249 0.1287 0.8256]} {[0.7919 0.0864 0.9448]} {[0.5224 0.9139 0.7971]} {[0.8930 0.9211 0.4165]} {[0.2960 0.8731 0.0686]} {[0.5109 0.1940 0.9486]} {[0.2114 0.7756 0.2927]}
{[0.9292 0.7464 0.9849]} {[0.7373 0.3576 0.0823]} {[0.8953 0.1333 0.8866]} {[0.2273 0.7162 0.6679]} {[0.3011 0.9334 0.8106]} {[0.9188 0.1131 0.0673]} {[0.6429 0.4821 0.5120]} {[0.2072 0.3749 0.5819]} {[0.3450 0.3783 0.9527]} {[0.0296 0.6055 0.7094]} {[0.1990 0.4302 0.1943]} {[0.1467 0.4498 0.2049]} {[0.5036 0.0508 0.9752]} {[0.1671 0.4104 0.5694]} {[0.5888 0.4415 0.7965]} {[0.6223 0.5846 0.5447]} {[0.8236 0.4885 0.1215]} {[0.9703 0.3887 0.0183]} {[0.8649 0.9943 0.0015]} {[0.2415 0.3358 0.7310]} {[0.3409 0.7371 0.4723]} {[0.9866 0.2764 0.7661]} {[0.2456 0.9752 0.8331]} {[0.3264 0.6088 0.9664]} {[0.5120 0.0158 0.2393]} {[0.9590 0.4794 0.4923]} {[0.1408 0.9563 0.1251]} {[0.7101 0.2474 0.4939]} {[0.8497 0.3606 0.3267]} {[0.3959 0.0756 0.6827]}
{[0.8262 0.6918 0.5471]} {[0.8755 0.3083 0.4668]} {[0.2692 0.9491 0.9485]} {[0.7312 0.0940 0.7889]} {[0.6232 0.9140 0.2606]} {[0.0974 0.1642 0.1264]} {[0.8204 0.4193 0.3712]} {[0.8510 0.2695 0.2089]} {[0.9329 0.4857 0.7534]} {[0.5284 0.4826 0.3174]} {[0.8365 0.0226 0.9623]} {[0.0121 0.9591 0.2520]} {[0.4461 0.2421 0.1642]} {[0.2766 0.1248 0.5843]} {[0.1882 0.5491 0.3692]} {[0.1296 0.0749 0.2469]} {[0.5580 0.4763 0.2130]} {[0.0448 0.5313 0.5185]} {[0.2583 0.5596 0.3773]} {[0.6429 0.8037 0.0475]} {[0.2039 0.0803 0.7987]} {[0.6727 0.4732 0.9227]} {[0.4730 0.8781 0.2739]} {[0.5806 0.6633 0.4859]} {[0.2127 0.0358 0.1055]} {[0.8714 0.5096 0.3305]} {[0.4656 0.2529 0.8804]} {[0.1039 0.9658 0.0965]} {[0.2534 0.6915 0.5815]} {[0.8169 0.1143 0.7607]}
{[0.3358 0.3659 0.0847]} {[0.8248 0.0630 0.7478]} {[0.0859 0.4268 0.5120]} {[0.2942 0.6225 0.1769]} {[0.6562 0.2325 0.7635]} {[0.7559 0.9618 0.9766]} {[0.9743 0.5746 0.1363]} {[0.3268 0.0317 0.5223]} {[0.9183 0.0887 0.9893]} {[0.5820 0.0884 0.4620]} {[0.2774 0.3369 0.7259]} {[0.7810 0.0557 0.5424]} {[0.6290 0.7688 0.2438]} {[0.6322 0.8649 0.3898]} {[0.2204 0.8559 0.2658]} {[0.5622 0.2340 0.7919]} {[0.6474 0.1660 0.1564]} {[0.8515 0.9651 0.3565]} {[0.3523 0.2730 0.5026]} {[0.4541 0.6099 0.8491]} {[0.0574 0.2221 0.4081]} {[0.5365 0.6588 0.2323]} {[0.7945 0.0529 0.7380]} {[0.0260 0.8984 0.7425]} {[0.9261 0.9174 0.9308]} {[0.7356 0.2066 0.1395]} {[0.1735 0.2151 0.2176]} {[0.4628 0.7948 0.6768]} {[0.1423 0.1103 0.3072]} {[0.8532 0.4817 0.1074]}
% first element of the vector in each cell of C:
result = cellfun(@(x)x(1),C)
result = 400×30
0.4837 0.8740 0.1324 0.6612 0.4619 0.7118 0.2325 0.0200 0.4560 0.1519 0.8171 0.7354 0.3328 0.8574 0.8225 0.7205 0.0384 0.9788 0.9149 0.2323 0.2986 0.8800 0.0667 0.6787 0.1189 0.1945 0.7551 0.6601 0.0305 0.2559
0.8256 0.4592 0.7049 0.4509 0.0687 0.7839 0.7122 0.7732 0.5106 0.3814 0.8269 0.4651 0.7178 0.0601 0.1606 0.8022 0.3695 0.4676 0.5443 0.0107 0.4242 0.0932 0.2591 0.0037 0.4344 0.8503 0.6300 0.7369 0.9386 0.8376
0.5549 0.4091 0.0982 0.7266 0.8680 0.0748 0.5388 0.3071 0.8893 0.1695 0.3605 0.6311 0.7511 0.4553 0.8662 0.1720 0.4470 0.7851 0.4080 0.4649 0.6417 0.4702 0.9411 0.0912 0.5545 0.3380 0.1652 0.2722 0.5397 0.5722
0.0788 0.3883 0.3312 0.6314 0.8679 0.9967 0.9261 0.5456 0.1639 0.2139 0.0530 0.5565 0.3360 0.5524 0.8465 0.7286 0.4273 0.2620 0.8590 0.4911 0.9668 0.1840 0.5850 0.1206 0.5714 0.6423 0.9187 0.4693 0.9607 0.3223
0.4740 0.7031 0.0956 0.7025 0.2697 0.6983 0.4640 0.7186 0.9529 0.1031 0.9618 0.5651 0.0930 0.8350 0.2929 0.0082 0.8387 0.2495 0.7764 0.0752 0.3261 0.6248 0.9437 0.5454 0.9168 0.2736 0.4397 0.7255 0.8021 0.4656
0.5338 0.7526 0.5498 0.4832 0.8979 0.8777 0.0600 0.7067 0.0356 0.8490 0.9712 0.0492 0.2202 0.3548 0.0882 0.4211 0.2338 0.2085 0.4386 0.6316 0.9799 0.9853 0.5281 0.2062 0.5461 0.3105 0.2766 0.3531 0.6678 0.9592
0.6690 0.4193 0.5614 0.0265 0.2019 0.6552 0.3658 0.4005 0.7309 0.8173 0.8237 0.1971 0.4563 0.3923 0.4221 0.4862 0.6172 0.5014 0.1152 0.8745 0.2982 0.1953 0.8233 0.2180 0.5983 0.2572 0.0465 0.8519 0.1423 0.4876
0.8101 0.7243 0.5799 0.4406 0.4264 0.0973 0.6620 0.4242 0.9587 0.7218 0.3534 0.2709 0.1132 0.7253 0.2636 0.1935 0.2115 0.2095 0.0884 0.3745 0.8799 0.1194 0.6464 0.5217 0.4975 0.0436 0.0452 0.4353 0.4962 0.0980
0.3931 0.7120 0.9851 0.0779 0.6079 0.7469 0.6458 0.0630 0.0923 0.1773 0.1143 0.3538 0.9882 0.1814 0.3046 0.0837 0.6012 0.2084 0.4567 0.5604 0.1455 0.8098 0.4093 0.8472 0.3292 0.3222 0.9638 0.3620 0.9914 0.4044
0.8212 0.6847 0.6415 0.6561 0.4268 0.9211 0.8204 0.7044 0.1864 0.8216 0.8203 0.4255 0.4428 0.7608 0.8108 0.7484 0.9059 0.0598 0.5630 0.3571 0.3091 0.5101 0.9889 0.1225 0.3239 0.0960 0.2005 0.0221 0.4858 0.9786
% or, first element of the vector in each cell of the first column of C:
result = cellfun(@(x)x(1),C(:,1))
result = 400×1
0.4837
0.8256
0.5549
0.0788
0.4740
0.5338
0.6690
0.8101
0.3931
0.8212
6 Comments
Chiara Gigoli
on 14 Jun 2022
Hi Voss,
Thank you for your answer! I did the same thing, but in this way I obtain the first element of ALL columns... But if I want only the first element of the first column?
Sorry for the stupid question, thank you in advance
Chiara
Voss
on 14 Jun 2022
I have edited my answer to show that scenario as well (use C(:,1) instead of C in the call to cellfun).
Chiara Gigoli
on 14 Jun 2022
I already tried, but this error appears:
"Index exceeds the number of array elements. Index must not exceed 0.
Error in @(x)x(1)"
Could it be because I have some blank cells?
I saw a topic in which they say to use this structure to replace blank cells with zeros:
idx = ~cellfun('isempty',C);
result = zeros(size(C))
Voss
on 14 Jun 2022
"Could it be because I have some blank cells?"
Yes, exactly.
You can replace the blank cells with [0 0 0] like this:
C(cellfun(@isempty,C)) = {[0 0 0]};
Or maybe it's better to use a 1x3 array of NaNs instead of zeros (in particular this is better if your data may contain [0 0 0] but will never contain [NaN NaN NaN]):
C(cellfun(@isempty,C)) = {NaN(1,3)};
Or since you just need the first element of the array in each cell, replace blank cells with a single NaN:
C(cellfun(@isempty,C)) = {NaN};
Chiara Gigoli
on 14 Jun 2022
Thank you very much to be so kind and patient.
This solved my question.
Voss
on 14 Jun 2022
You're welcome! I'm glad it's working now!
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)