How to substract a value from each row in a cell in Matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a cell with dimension 41X41 as shown below
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1133350/image.png)
that has values equal to 1, it means all its values are equal to ones as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1133355/image.png)
Based on many values, I could not include it here in one figure, but its dimension is 41 x 41.
What I was trying to do is calculate the number of ones in each row minus one as shown in the snippet of line code below:
ccc = sum(isSmaller{cc,:} == 1)-1
In order to get 1 row with 40 columns that have 40s. as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1133360/image.png)
My problem is instead of 40 columns is still showing 41 columns as indicated below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1133365/image.png)
May I get assistance, please? I need it to be 1 row with 40 columns. After that, I need to sum all the 40s in this ccc = 1x40.
Below is my try:
for cc = 1:length(isSmaller)
ccc = sum(isSmaller{cc,:} == 1)-1
end
2 Kommentare
Soufian MELLAHI
am 22 Sep. 2022
Hello,
I think you misunderstand that the size of your table is 41 by dimension since it's square. I am not sure to understand your problem. Anyways if you want to fetch daya from ii to jj you can just do it simply like : tmp=ccc(ii:jj);% tampon variable ccc=tmp;% retrieval of desired dimension you can just replace ii and jj by the indexes from where ypi want to extract data. For instance ii=1 & jj=40 to extract the first 40 elements of your row vector.
I hope it answers your question
Antworten (1)
Soufian MELLAHI
am 22 Sep. 2022
Bearbeitet: Soufian MELLAHI
am 22 Sep. 2022
Hello, I think you misunderstand that the size of your table is 41 by dimension since it's square. I am not sure to understand your problem. Anyways if you want to fetch data from ii to jj you can just do it simply like : tmp=ccc(ii:jj);% tampon variable ccc=tmp;% retrieval of desired dimension you can just replace ii and jj by the indexes from where ypi want to extract data. For instance ii=1 & jj=40 to extract the first 40 elements of your row vector. I hope it answers your question
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!