Insert value at particular index of cell array in a loop
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to create an cell array of unequal length in matlab.I create an empty cell and add values like
temp = {[1,2,3,21,23]};{[11,2,10]};{1};
just like hash tables having unequal length of linked list while calculating values in a loop.
For my problem statement i want to create a new row matrix for every new set of values .For example i got r= 23,i put that in a matrix next time
r= 40 i create new matrix for all values lying within ht e range of +,- 1.
Since, we cant create run time new matrix of unequal length.
As in this case i can get
c = [1,1.5,1.6,1.7];[23,22,21];[40,41]
Due to unequal length ,matrix cant solve this issue.cell array can but how to insert value at matrix of range 40.
0 Kommentare
Antworten (1)
KSSV
am 12 Aug. 2020
You can insert a number in an array on knowing the value of the element and at what position you want to insert the value.
A = [1 2 0 6 7 1] ;
val = 0.5 ; % insert this value at indiex idx
idx = 2 ; % index where to insert the value val
B = [A(1:idx-1) val A(idx:end)] ;
Now you can run a loop for each cell array using the above procedure to insert values.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!