how to convert data which is saved as cell should be converted into double type how to do it?

1 view (last 30 days)
I have extracted Image names means I have separated the image names and extensions and saved in an array. now i should convert those names into numbers.If I have converted those names into numbers I can concatenate th0se names at the end column of the database.
iam attaching my code below... plz help
load('Image_names.mat');
for i=1:size(Image_names);
[~,name{i}]=fileparts(Image_names{i});
Imagename=name';
end

Answers (1)

Stephen23
Stephen23 on 28 Sep 2018
Edited: Stephen23 on 28 Sep 2018
An explicit loop is not required to use fileparts with a cell array:
[P,N] = cellfun(@fileparts,Imagename,'uni',0)
But note that none of the character vectors in your sample cell array contain paths:
>> load('Imagename.mat')
>> [P,N] = cellfun(@fileparts,Imagename,'uni',0);
>> all(cellfun(@isempty,P))
ans = 1
>> isequal(Imagename,N)
ans = 1
"how to convert data which is saved as cell should be converted into double type how to do it?"
Using str2double:
>> vec = str2double(Imagename)
vec =
Columns 1 through 23:
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
Columns 24 through 46:
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
Columns 47 through 69:
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
Columns 70 through 92:
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
Columns 93 through 115:
1686 1687 1688 1689 1690 1691 1692 1694 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671
Columns 116 through 138:
2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694
Columns 139 through 161:
2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717
Columns 162 through 184:
2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740
Columns 185 through 207:
2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2766 9031 9032 9034 9035 9037 9038 9039
Columns 208 through 230:
9040 9041 9042 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063
Columns 231 through 253:
9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086
Columns 254 through 276:
9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109
Columns 277 through 299:
9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132
Columns 300 through 322:
9133 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
Columns 323 through 345:
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
Columns 346 through 368:
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
Columns 369 through 391:
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
Columns 392 through 414:
891 892 893 894 895 896 897 898 9283 700 701 702 703 704 705 706 707 708 709 710 711 712 713
Columns 415 through 437:
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
Columns 438 through 460:
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
Columns 461 through 483:
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
Columns 484 through 500:
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
>> class(vec)
ans = double
>> size(vec)
ans =
1 500

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!