How to add values from vertcat to a script

1 回表示 (過去 30 日間)
Tipu Sultan
Tipu Sultan 2019 年 4 月 26 日
編集済み: Stephen23 2019 年 4 月 29 日
I have script which calls a function and the return values of the function are stored in this way:
M = vertcat(C{:});
C is 1*99 cell and each cell has 4 values.Now I want to store individual value of 1st column to an array 2nd column to another array and so on.So is it possible to do so?
  11 件のコメント
Tipu Sultan
Tipu Sultan 2019 年 4 月 29 日
Thanks @stephen.
I changed the code as follows:
D = 'C:\Users\Tipu_Standard\Desktop\My_project_cropped_images1';
S = dir(fullfile(D,'Original*.jpg')); % pattern to match filenames.
N = numel(S);
C = cell(1,N);
for k = 1:N
F = fullfile(D,S(k).name);
I = imread(F);
%C{k} = fun1(I);
Zvec = zeros(1,20);
Dvec = zeros(1,20);
Avec = zeros(1,20);
[Zvec(k),Dvec(k),Avec(k)] = fun1(I);
end
M = vertcat(C{:});
Command window gives me following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in funCall (line 12)
[Zvec(k),Dvec(k),Avec(k)] = fun1(I);
Is there any problem that I am not able to locate!
Stephen23
Stephen23 2019 年 4 月 29 日
編集済み: Stephen23 2019 年 4 月 29 日
Move the preallocation before the loop (just like the preallocation documentation shows):
D = 'C:\Users\Tipu_Standard\Desktop\My_project_cropped_images1';
S = dir(fullfile(D,'Original*.jpg')); % pattern to match filenames.
N = numel(S);
Zvec = zeros(1,N);
Dvec = zeros(1,N);
Avec = zeros(1,N);
for k = 1:N
F = fullfile(D,S(k).name);
I = imread(F);
[Zvec(k),Dvec(k),Avec(k)] = fun1(I);
end
You will also need to adjust the sizes of the output arrays AND the indexing to suit the sizes of the output arguments: if they are non-scalar then you will continue to get errors.
I do not have your data, you will have to check this yourself. After that, adjust the sizes of the output arrays. If the sizes change on between iterations, use cell arrays for the appropriate array/s (in fact if you just want to get your code working, use cell arrays for all three outputs).

サインインしてコメントする。

回答 (1 件)

madhan ravi
madhan ravi 2019 年 4 月 26 日
Wanted = num2cell(M,1)
[a,b,c,d]=deal(Wanted{:})
  3 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 26 日
That seems like a different question , I answered to the question you originally asked. It’s better you post it as a separate question.
Tipu Sultan
Tipu Sultan 2019 年 4 月 28 日
@madhan I posted the question but it was closed due to duplicate!
So please help me with the problem.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by