Automatic building of an array

11 views (last 30 days)
Hey all,
Below is my function. I need to build the array automatically for the user input.
function suri1(Measuring_Data(:,7))
%User input
X = {1, 2,'Node1'; 3, 4, 'Node2'; 5, 6, 'Node3'}; % different for different users
n = 10;
d_T= 1 ;
t = 200;
S = load('Measuring_Data.mat');
f = 0:d_T:(t-1)*d_T;
p = cell2mat(X(:,1));
q = cell2mat(X(:,2));
disp(p);
disp(q);
T_Vorgabe = zeros(1,length(f)); % Row vector
for plotnumber = 1:n
c = find(p == plotnumber,1);
if ~isempty(c)
c = plotnumber;
for plotnumber1 = 1:n
c1 = find(q == plotnumber1,1);
if ~isempty(c1)
c1 = plotnumber1;
T_Vorgabe{c}(1,:) = S(c1,1); % May be worng syntax , All the values of the measuring data should be copied to T_Vorgabe as a row %vector or row cell array, c is the user input number to build the vector or cell array of different names
end
end
end
end
figure
hold('on')
for plotnumber2 = 1:n
c2 = find(p == plotnumber,1)
if ~isempty(c2)
c2 = plotnumber;
plot(f(1:15:end)/200, T_Vorgabe{c2}); % Slover should plot all the values of T_Vorgabe(row vector or row cell array.
end
end
end
Here T_Vorgabe{c2} will be cell array. Now while plotting the T_Vorgabe solver should get the all the values stored from the respective cell arrayT_Vorgabe{c2}.
My questions are,
How to make T_Vorgabe as a row vector, or row cell array of different names according to user input?
Like below
T_Vorgabe{1}=[1,2,3,...,2920]
T_Vorgabe{2}=[2921,2922,2923,...,5840] etc
Any suggestions and answers are most welcomed.
Thanks in advance
  6 Comments
surendra kumar Aralapura mariyappa
Now I realized the importance of your suggestion after I ran my program. It is taking too much time to do compilation. It is the time for me to make my code according to your suggestion.
Anyways thank you.

Sign in to comment.

Accepted Answer

Bob Thompson
Bob Thompson on 28 Jun 2019
'T_Vorgabe{c}(1,:) = S(c1,1);
I just need to know whether it is correct or not!. '
As I mentioned before, the concept is sound, and it should produce something like what you are looking for. I cannot tell you if it is 'correct' because minor adjustments may be needed to personalize the code to your specific dataset. I suspect this line will not actually have to be changed, but perhaps your definition of c and c1 will need to be changed. That is something you will have to tackle though when you have an actual sample of data to work with. That's just how debugging works.
'Second question is How to access the indicies of element of cell array?'
For information on how to work with cell indices I recommend this link. If you still need additional help, please be more specific.
  1 Comment
surendra kumar Aralapura mariyappa
@ Nbob, ' please be more specific.'
I think at least I will get the solution to my problem now.
%T1(:,1) = T1(:,1)+ 20; % Adding the ambient temperature
%f = 0:d_T:(t-1)*d_T; %d_T is step time
% Here d_T = 1 and t = 200 iterations. %T1 is a temperature vector for 200 iterations
load('Measuring_Data.mat');
[f,T] = Samplemodel_Instat('Measuring_Data.mat');
[Lambda, A, B, D,V,H, Rho,cP,P, M, A1,O, X, M_1] = Matrix_Samplemodel;
% X = { 3 6 'Node1': 4 9 'Node2'}; Like this
p = cell2mat(X(:,1));
q = cell2mat(X(:,2));
disp(p);
disp(q);
n = size(A,1);
T_Vorgabe = zeros(1,length(f)); % I am not sure whether the preallocation is correct or not!.
for plotnumber = 1:n
c = find(p == plotnumber,1);
if ~isempty(c)
c = plotnumber;
for plotnumber1 = 1:n
c1 = find(q == plotnumber1,1);
if ~isempty(c1)
c1 = plotnumber1;
T_Vorgabe{c}(1,:) = Measuring_Data(c1, 1); % Here Measuring_Data should be copied to %T_Vorgabe each time with new variable name according to the user input.
end
end
end
end
%then all the T_Vorgabe{c} should be plotted.
plot(f(1:200:end)/3600,T_Vorgabe{c}(1:200:end),'Color','k','LineWidth',2,'LineStyle','--');
end
I hope now it is understandable.
this is the error I am getting:
"Cell contents assignment to a non-cell array object.
Error in suri1 (line 22)
T_Vorgabe{c}(1,:) = Measuring_Data(c1, 1);"
I just need to copy the measuring values to new T_Vorgabe variable like T_Vorgabe.1, T_Vorgabe.2 each time and plot it.
Any suggestions and answered are most welcomed
Thanks in advance.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!